Great Party
Time limit1sMemory limit1024 MB
For each query range [l, r], count the sub-segments whose stone piles give the first player a win in the merge-and-remove game.
- Level
Hard9 of 10
- Topics
- Game theory, Bit manipulation, Two pointers
- Solved
- No attempts yet
Problem
Grammy joined a great party.
There is an interesting game at the party. There are piles of stones on the table. The -th pile has stones. Two players take turns operating the stones.
On each turn, a player does the following two steps:
- Select a non-empty pile and remove a positive number of stones from it.
- Either keep the remaining stones in that pile, or merge all of them into another non-empty pile.
A player who cannot operate loses the game.
Grammy has questions. For each question, count the sub-segments of for which the first player wins when the piles in that sub-segment are played alone as a game.
Input
The first line contains two integers and ().
The second line contains integers ().
The -th of the next lines contains two integers and ().
Output
The output contains lines. Each line contains a single integer, the answer to the question.