QOJ.ac

QOJ

Límite de tiempo: 1 s Límite de memoria: 1024 MB Puntuación total: 100

#3734. 括号

Estadísticas

Bobo 有一个长度为 $n$ 的平衡括号序列 $P = p_1p_2\dots p_n$,以及 $q$ 个询问。

第 $i$ 个询问是询问在交换 $p_{a_i}$ 和 $p_{b_i}$ 后,$P$ 是否仍然保持平衡。 注意,每个询问都是独立的,即询问之间互不影响。

括号序列 $S$ 是平衡的,当且仅当:

  1. $S$ 为空;
  2. 或者存在平衡括号序列 $A, B$ 使得 $S = AB$;
  3. 或者存在平衡括号序列 $S'$ 使得 $S = (S')$。

输入格式

输入包含最多 $30$ 组数据。对于每组数据:

第一行包含两个整数 $n, q$ ($2 \leq n \leq 10^5, 1 \leq q \leq 10^5$)。

第二行包含 $n$ 个字符 $p_1p_2\dots p_n$。

接下来的 $q$ 行中,第 $i$ 行包含两个整数 $a_i, b_i$ ($1 \leq a_i, b_i \leq n, a_i \neq b_i$)。

输出格式

对于每个询问,如果 $P$ 仍然平衡,输出 "Yes",否则输出 "No"。

样例

样例输入 1

4 2
(())
1 3
2 3
2 1
()
1 2

样例输出 1

No
Yes
No

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.