CF1896D.Ones and Twos

普及+/提高

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

You are given a 11-indexed array aa of length nn where each element is 11 or 22.

Process qq queries of the following two types:

  • "1 s": check if there exists a subarray†^{\dagger} of aa whose sum equals to ss.
  • "2 i v": change aia_i to vv.

†^{\dagger} An array bb is a subarray of an array aa if bb can be obtained from aa 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.

给你一个长度为 nn 的、从 11 开始编号的数组 aa,其中每个元素均为 11 或 22。

你需要处理 qq 个如下两种类型的查询:

  • “1 s”:检查数组 aa 中是否存在一个子数组†^{\dagger},其元素之和等于 ss。
  • “2 i v”:将 aia_i 修改为 vv。

†^{\dagger} 若数组 bb 可通过从数组 aa 的开头删除若干(可能为零个或全部)元素,并从结尾删除若干(可能为零个或全部)元素而得到,则称 bb 是 aa 的一个子数组。特别地,任意数组是其自身的子数组。

输入格式

Each test contains multiple test cases. The first line contains a single integer tt (1≤t≤1041 \le t \le 10^4) — the number of test cases. The description of the test cases follows.

The first line of each test case contains two integers nn and qq (1≤n,q≤1051\le n,q\le 10^5) — the length of array aa and the number of queries.

The second line of each test case contains nn integers a1,a2,…,ana_1,a_2,\ldots,a_n (aia_i is 11 or 22) — the elements of array aa.

Each of the following qq lines of each test case contains some integers. The first integer op\mathrm{op} is either 11 or 22.

  • If op\mathrm{op} is 11, it is followed by one integer ss (1≤s≤2n1 \leq s \leq 2n).
  • If op\mathrm{op} is 22, it is followed by two integers ii and vv (1≤i≤n1 \leq i \leq n, vv is 11 or 22).

It is guaranteed that the sum of nn and the sum of qq over all test cases both do not exceed 10510^5.

每个测试包含多个测试用例。第一行包含一个整数 tt(1≤t≤1041 \le t \le 10^4),表示测试用例的数量。随后是各测试用例的描述。

每个测试用例的第一行包含两个整数 nn 和 qq(1≤n,q≤1051\le n,q\le 10^5),分别表示数组 aa 的长度和查询次数。

每个测试用例的第二行包含 nn 个整数 a1,a2,…,ana_1,a_2,\ldots,a_n(每个 aia_i 为 11 或 22),表示数组 aa 的元素。

每个测试用例接下来的 qq 行中,每行包含若干整数。第一个整数 op\mathrm{op} 为 11 或 22:

  • 若 op=1\mathrm{op} = 1,则其后跟一个整数 ss(1≤s≤2n1 \leq s \leq 2n);
  • 若 op=2\mathrm{op} = 2,则其后跟两个整数 ii 和 vv(1≤i≤n1 \leq i \leq n,且 vv 为 11 或 22)。

保证所有测试用例的 nn 之和与 qq 之和均不超过 10510^5。

输出格式

For each query with op=1\mathrm{op}=1, output "YES" in one line if there exists a subarray of aa whose sum is equals to ss, 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\mathrm{op}=1 的查询,如果数组 aa 中存在一个子数组,其元素和等于 ss,则在一行中输出 “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=5a_1+a_2+a_3=2+1+2=5.
  • The answer for the second query is "YES" because a1+a2+a3+a4=2+1+2+1=6a_1+a_2+a_3+a_4=2+1+2+1=6.
  • The answer for the third query is "NO" because we cannot find any subarray of aa whose sum is 77.
  • After the fourth query, the array aa becomes [2,1,2,2,2][2,1,2,2,2].
  • The answer for the fifth query is "YES" because a2+a3+a4+a5=1+2+2+2=7a_2+a_3+a_4+a_5=1+2+2+2=7.

考虑第一个例子:

  • 第一个查询的答案是“YES”,因为 a1+a2+a3=2+1+2=5a_1+a_2+a_3=2+1+2=5。
  • 第二个查询的答案是“YES”,因为 a1+a2+a3+a4=2+1+2+1=6a_1+a_2+a_3+a_4=2+1+2+1=6。
  • 第三个查询的答案是“NO”,因为我们无法在数组 aa 中找到和为 77 的任意子数组。
  • 第四个查询之后,数组 aa 变为 [2,1,2,2,2][2,1,2,2,2]。
  • 第五个查询的答案是“YES”,因为 a2+a3+a4+a5=1+2+2+2=7a_2+a_3+a_4+a_5=1+2+2+2=7。

输入解题思路,AI测评打分。不知道怎么写?

首页