CF BUDDY
← Problems·

1896D · Ones and Twos

1700 · binary search, data structures, divide and conquer

Problem: 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.

Input Format: Each test contains multiple test cases. The first line contains a single integer tt (1t1041 \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 (1n,q1051\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 (1s2n1 \leq s \leq 2n).
  • If op\mathrm{op} is 22, it is followed by two integers ii and vv (1in1 \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.

Output Format: 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.

Note: 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.

Sample Cases

Case 1

Input

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

Output

YES
YES
NO
YES
YES
NO

Similar problems

00:00:00
Loading editor…
Welcome! I'm your coding tutor for this problem. Use the chips below to reveal stored hints or get AI feedback on your code. I'll guide you step by step — never giving away the solution.

Sign in to unlock AI tutor feedback