Good Sequence
Time limit4sMemory limit1024 MB
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 of length contains zeros and ones. Apply the following operation or more times. If can be made to contain , then is called a good sequence.
- Pick 4 consecutive integers from and call them , , , in order. Let be the length of before the operation.
- Delete , , , and insert , in their place, in that order.
- In other words, becomes .
A sequence of length is given, with zeros and ones. After each query below, determine whether is a good sequence.
- : Flip for every with . That is, change to and to . The number of ones and the number of zeros in the range are guaranteed to be equal.
Input
The first line contains the integer .
The second line contains integers , separated by spaces.
The third line contains the integer .
Each of the next lines contains two integers and , separated by a space.
Output
Print lines. On line , print YES if is a good sequence after applying the first queries in order, and NO otherwise.