Under construction

Still being built. Things may change

Good Sequence

Time limit4sMemory limit1024 MB

Summary
After each range flip of a balanced 0/1 sequence, decide whether the four-element operation can reduce it to a sequence that contains N.
Level

Medium7 of 10

Topics
Array, Prefix sum, Segment tree
Solved
No attempts yet

Problem

A sequence AA of length 2N2N contains NN zeros and NN ones. Apply the following operation 00 or more times. If AA can be made to contain NN, then AA is called a good sequence.

  • Pick 4 consecutive integers from AA and call them xx, yy, zz, ww in order. Let LL be the length of AA before the operation.
  • Delete xx, yy, zz, ww and insert ww, x+yx+y in their place, in that order.
  • In other words, A1,A2,⋯ ,x,y,z,w,⋯ ,ALA_1, A_2, \cdots, x, y, z, w, \cdots, A_L becomes A1,A2,⋯ ,w,x+y,⋯ ,ALA_1, A_2, \cdots, w, x+y, \cdots, A_L.

A sequence BB of length 2N2N is given, with NN zeros and NN ones. After each query below, determine whether BB is a good sequence.

  • l rl\ r: Flip BiB_i for every ii with l≤i≤rl \le i \le r. That is, change 11 to 00 and 00 to 11. The number of ones and the number of zeros in the range [l,r][l, r] are guaranteed to be equal.

Input

The first line contains the integer NN.

The second line contains 2N2N integers B1,B2,⋯ ,B2NB_1, B_2, \cdots, B_{2N}, separated by spaces.

The third line contains the integer QQ.

Each of the next QQ lines contains two integers ll and rr, separated by a space.

Output

Print Q+1Q+1 lines. On line ii, print YES if BB is a good sequence after applying the first i−1i-1 queries in order, and NO otherwise.

Constraints

  • 2≤N≤2×1052\le N\le 2\times 10^5
  • Bi∈{0,1}B_i\in\{0,1\} (1≤i≤2N)(1\le i\le 2N)
  • ∑i=12NBi=N\sum_{i=1}^{2N} B_i=N
  • 0≤Q≤2×1050\le Q\le 2\times 10^5
  • 1≤l≤r≤2N1\le l\le r\le 2N

Examples1

  1. Example 1

    Input
    3
    1 1 0 0 1 0
    2
    4 5
    1 6
    
    Expected output
    NO
    YES
    NO