CF1340F.Nastya and CBS

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Nastya is a competitive programmer, but she is only studying now. Recently, Denis told her about the way to check if the string is correct bracket sequence. After that, unexpectedly, Nastya came up with a much more complex problem that Denis couldn't solve. Can you solve it?

A string ss is given. It consists of kk kinds of pairs of brackets. Each bracket has the form tt — it is an integer, such that 1tk1 \leq |t| \leq k . If the bracket has a form tt , then:

  • If t>0t > 0 , then it's an opening bracket of the type tt .
  • If t<0t < 0 , then it's a closing bracket of the type t-t .

Thus, there are kk types of pairs of brackets in total.

The queries need to be answered:

  1. Replace the bracket at position ii with the bracket of the form tt .
  2. Check if the substring from the ll -th to rr -th position (including) is the correct bracket sequence.

Recall the definition of the correct bracket sequence: - An empty sequence is correct.

  • If AA and BB are two correct bracket sequences, then their concatenation " AA BB " is also correct bracket sequence.
  • If AA is the correct bracket sequence, cc (1ck)(1 \leq c \leq k) is a type of brackets, then the sequence " cc AA c-c " is also correct bracket sequence.

输入格式

The first line contains an integer nn (1n105)(1 \leq n \leq 10^5) — length of string and kk (1kn)(1 \leq k \leq n) — the number of kinds of pairs of brackets.

The second line contains string ss of length nnnn integers s1,s2,,sns_1, s_2, \ldots, s_n (1sik)(1 \leq |s_i| \leq k)

The third line contains single integer qq (1q105)(1 \leq q \leq 10^5) — the number of queries.

Each of the following qq lines describes the queries:

  • 11 ii tt - query of the 11 type (1in,1tk)(1 \leq i \leq n, 1 \leq |t| \leq k) .
  • 22 ll rr - query of the 22 type (1lrn)(1 \leq l \leq r \leq n) .

输出格式

For each query of 22 type, output "Yes" if the substring from the query is the correct bracket sequence and "No", otherwise.

All letters can be displayed in any case.

输入输出样例

  • 输入#1

    2 1
    1 -1
    1
    2 1 2

    输出#1

    Yes
  • 输入#2

    2 2
    1 -2
    1
    2 1 2

    输出#2

    No
  • 输入#3

    6 2
    1 2 -2 -1 1 -1
    3
    2 1 6
    2 1 4
    2 2 5

    输出#3

    Yes
    Yes
    No
  • 输入#4

    2 2
    -1 1
    4
    2 1 2
    1 1 1
    1 2 -1
    2 1 2

    输出#4

    No
    Yes

说明/提示

In the fourth test, initially, the string is not a correct bracket sequence, so the answer to the first query is "No". After two changes it will be equal to " 11 1-1 ", so it is a correct bracket sequence and the answer to the fourth query is "Yes".

首页