Game Theory
시간 제한1초메모리 제한1024 MB
구간 뒤집기가 일어날 때마다 모든 비트가 0이 될 때까지 이 뒤집기 게임이 몇 번 움직이는지 구한다.
문제
For a string of bits (i.e., zeros and ones), Bobo computes the -value of by playing the following game.
- If all the bits are zero, the game ends.
- If there are ones in the bit string, Bobo flips the -th bit, i.e., .
- The -value of the bit string is the number of flips Bobo has performed before the game ends.
Formally,
- If , .
- Otherwise, assuming that , where denotes the flip of the bit such as and .
Now, Bobo has a bit string subjecting to changes, where the -th change is to flip all the bits among for given , . Find the -value modulo of the bit string after each change.
입력
The input consists of several test cases terminated by end-of-file. For each test case,
The first line contains two integers and .
The second line contains bits .
For the following lines, the -th line contains two integers and .
출력
For each change, output an integer which denotes the -value modulo .
제한
- for each
- for each
- In each input, the sum of does not exceed . The sum of does not exceed .
힌트
For the first test case, the string becomes "100" after the first change. 100000. And it becomes "111" after the second change. 111110100000.