QOJ.ac

QOJ

実行時間制限: 1.0 s メモリ制限: 512 MB 満点: 100 ハック可能 ✓

#8491. a, ab, ba 字符串

統計

给定一个长度为 $n$ 的字符串 $S$,由字符 ‘a’ 和 ‘b’ 组成,以及 $q$ 次查询。查询分为两种类型:

  1. 将第 $i$ 个字符替换为相反的字符(即 ‘a’ 变为 ‘b’,‘b’ 变为 ‘a’)。
  2. 检查是否可以将从第 $l$ 个字符到第 $r$ 个字符的子串拆分为 ‘a’、‘ab’ 和 ‘ba’ 这几种子串。

对于每种第二类型的查询,输出查询结果。

输入格式

第一行包含一个整数 $n$ —— 字符串的长度 ($1 \le n \le 100\,000$)。 第二行包含字符串 $S$ 本身,由字符 ‘a’ 和 ‘b’ 组成。 第三行包含一个整数 $q$ —— 查询次数 ($1 \le q \le 100\,000$)。 接下来的 $q$ 行,每行以一个整数 $type$ 开头 —— 查询类型 ($1 \le type \le 2$)。 对于第一类查询,后面跟一个整数 $i$ ($1 \le i \le n$)。 对于第二类查询,后面跟一对整数 $l, r$ ($1 \le l \le r \le n$)。

输出格式

对于每个第二类查询,如果字符串可以按条件拆分,则输出 ‘YES’,否则输出 ‘NO’。

样例

输入 1

7
abbabba
4
2 3 4
2 3 5
1 6
2 3 7

输出 1

YES
NO
YES

说明

在第一个样例中,第一个查询的子串可以表示为 ‘ba’;第二个查询的子串 ‘bab’ 无法拆分为有效的子串;在第三个查询后,字符串变为 ‘abbabaa’,第四个查询的子串可以拆分为:‘ba|ba|a’。

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.