CF1896D.Ones and Twos
普及+/提高
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given a 1-indexed array a of length n where each element is 1 or 2.
Process q queries of the following two types:
- "1 s": check if there exists a subarray† of a whose sum equals to s.
- "2 i v": change ai to v.
† An array b is a subarray of an array a if b can be obtained from a by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. In particular, an array is a subarray of itself.
给你一个长度为 n 的、从 1 开始编号的数组 a,其中每个元素均为 1 或 2。
你需要处理 q 个如下两种类型的查询:
- “1 s”:检查数组 a 中是否存在一个子数组†,其元素之和等于 s。
- “2 i v”:将 ai 修改为 v。
† 若数组 b 可通过从数组 a 的开头删除若干(可能为零个或全部)元素,并从结尾删除若干(可能为零个或全部)元素而得到,则称 b 是 a 的一个子数组。特别地,任意数组是其自身的子数组。
输入格式
Each test contains multiple test cases. The first line contains a single integer t (1≤t≤104) — the number of test cases. The description of the test cases follows.
The first line of each test case contains two integers n and q (1≤n,q≤105) — the length of array a and the number of queries.
The second line of each test case contains n integers a1,a2,…,an (ai is 1 or 2) — the elements of array a.
Each of the following q lines of each test case contains some integers. The first integer op is either 1 or 2.
- If op is 1, it is followed by one integer s (1≤s≤2n).
- If op is 2, it is followed by two integers i and v (1≤i≤n, v is 1 or 2).
It is guaranteed that the sum of n and the sum of q over all test cases both do not exceed 105.
每个测试包含多个测试用例。第一行包含一个整数 t(1≤t≤104),表示测试用例的数量。随后是各测试用例的描述。
每个测试用例的第一行包含两个整数 n 和 q(1≤n,q≤105),分别表示数组 a 的长度和查询次数。
每个测试用例的第二行包含 n 个整数 a1,a2,…,an(每个 ai 为 1 或 2),表示数组 a 的元素。
每个测试用例接下来的 q 行中,每行包含若干整数。第一个整数 op 为 1 或 2:
- 若 op=1,则其后跟一个整数 s(1≤s≤2n);
- 若 op=2,则其后跟两个整数 i 和 v(1≤i≤n,且 v 为 1 或 2)。
保证所有测试用例的 n 之和与 q 之和均不超过 105。
输出格式
For each query with op=1, output "YES" in one line if there exists a subarray of a whose sum is equals to s, otherwise output "NO".
You can output the answer in any case (upper or lower). For example, the strings "yEs", "yes", "Yes", and "YES" will be recognized as positive responses.
对于每个操作类型 op=1 的查询,如果数组 a 中存在一个子数组,其元素和等于 s,则在一行中输出 “YES”;否则输出 “NO”。
你可以以任意大小写形式输出答案(大写或小写均可)。例如,字符串 “yEs”、“yes”、“Yes” 和 “YES” 均会被识别为肯定回答。
输入输出样例
输入#1
2 5 5 2 1 2 1 2 1 5 1 6 1 7 2 4 2 1 7 3 2 2 2 2 1 6 1 5
输出#1
YES YES NO YES YES NO
说明/提示
Consider the first example:
- The answer for the first query is "YES" because a1+a2+a3=2+1+2=5.
- The answer for the second query is "YES" because a1+a2+a3+a4=2+1+2+1=6.
- The answer for the third query is "NO" because we cannot find any subarray of a whose sum is 7.
- After the fourth query, the array a becomes [2,1,2,2,2].
- The answer for the fifth query is "YES" because a2+a3+a4+a5=1+2+2+2=7.
考虑第一个例子:
- 第一个查询的答案是“YES”,因为 a1+a2+a3=2+1+2=5。
- 第二个查询的答案是“YES”,因为 a1+a2+a3+a4=2+1+2+1=6。
- 第三个查询的答案是“NO”,因为我们无法在数组 a 中找到和为 7 的任意子数组。
- 第四个查询之后,数组 a 变为 [2,1,2,2,2]。
- 第五个查询的答案是“YES”,因为 a2+a3+a4+a5=1+2+2+2=7。
输入解题思路,AI测评打分。不知道怎么写?