CF1340F.Nastya and CBS
NOI/NOI+/CTSC
通过率:0%
时间限制:4.00s
内存限制:256MB
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 s is given. It consists of k kinds of pairs of brackets. Each bracket has the form t — it is an integer, such that 1≤∣t∣≤k. If the bracket has a form t, then:
- If t>0, then it's an opening bracket of the type t.
- If t<0, then it's a closing bracket of the type −t.
Thus, there are k types of pairs of brackets in total.
The queries need to be answered:
- Replace the bracket at position i with the bracket of the form t.
- Check if the substring from the l-th to r-th position (including) is the correct bracket sequence.
Recall the definition of the correct bracket sequence:
- An empty sequence is correct.
- If A and B are two correct bracket sequences, then their concatenation "A B" is also correct bracket sequence.
- If A is the correct bracket sequence, c (1≤c≤k) is a type of brackets, then the sequence "c A −c" is also correct bracket sequence.
娜斯佳是一名竞赛程序员,但她目前仍在学习阶段。最近,丹尼斯向她介绍了如何判断一个字符串是否为合法的括号序列。此后,出乎意料地,娜斯佳提出了一个复杂得多的问题,而丹尼斯无法解决。你能解决它吗?
给定一个字符串 s,它由 k 种括号对组成。每个括号的形式为 t —— 这是一个整数,满足 1≤∣t∣≤k。若某括号形式为 t,则:
- 若 t>0,则它是第 t 类的左括号;
- 若 t<0,则它是第 −t 类的右括号。
因此,总共有 k 种括号对。
需要回答以下两类查询:
- 将位置 i 处的括号替换为形式为 t 的括号;
- 检查从第 l 个位置到第 r 个位置(含端点)的子串是否为合法的括号序列。
回顾合法括号序列的定义:
- 空序列是合法的;
- 若 A 和 B 均为合法括号序列,则它们的拼接 "A B" 也是合法括号序列;
- 若 A 是合法括号序列,c (1≤c≤k) 是一种括号类型,则序列 "c A −c" 也是合法括号序列。
输入格式
The first line contains an integer n (1≤n≤105) — length of string and k (1≤k≤n) — the number of kinds of pairs of brackets.
The second line contains string s of length n — n integers s1,s2,…,sn (1≤∣si∣≤k)
The third line contains single integer q (1≤q≤105) — the number of queries.
Each of the following q lines describes the queries:
- 1 i t - query of the 1 type (1≤i≤n,1≤∣t∣≤k).
- 2 l r - query of the 2 type (1≤l≤r≤n).
第一行包含两个整数 n (1≤n≤105) — 字符串长度,以及 k (1≤k≤n) — 括号对的种类数。
第二行包含一个长度为 n 的字符串 s — n 个整数 s1,s2,…,sn (1≤∣si∣≤k)。
第三行包含一个整数 q (1≤q≤105) — 查询次数。
接下来的 q 行每行描述一个查询:
- 1 i t — 第 1 类查询 (1≤i≤n,1≤∣t∣≤k)。
- 2 l r — 第 2 类查询 (1≤l≤r≤n)。
输出格式
For each query of 2 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.
对于每个类型为 2 的查询,如果查询指定的子串是合法的括号序列,则输出 “Yes”,否则输出 “No”。
所有字母可以以任意大小写形式显示。
输入输出样例
输入#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 "1 −1", so it is a correct bracket sequence and the answer to the fourth query is "Yes".
在第四个测试中,初始字符串不是一个合法的括号序列,因此第一个查询的答案是“No”。经过两次修改后,它将变为“1 −1”,此时它成为一个合法的括号序列,因此第四个查询的答案是“Yes”。
输入解题思路,AI测评打分。不知道怎么写?