Card Game
Time limit3sMemory limit2048 MB
- Level
Not classified yet
- Solved
- No attempts yet
Statement
Randias is playing a card game. Each card has a number written on it. For cards with numbers , Randias plays the game as follows.
Initially, all cards are in his hand. Randias maintains a card sequence, which starts empty. In the -th operation, he puts the -th card (number ) at the end of the sequence. Then:
- If no other card in the sequence has the number , the -th operation ends.
- Otherwise, let the -th card in the sequence have the number . Randias takes away all cards from the -th card through the newly placed card, inclusive.
For example, let and let the card sequence initially. After operation 1, . After operation 2, . After operation 3, . After operation 4, (cards 1, 3, 1 are taken away). After operation 5, (cards 2, 2 are taken away). After operation 6, .
Randias is given cards and queries. The -th query is a pair . For each query, find how many cards remain in the sequence if the initial list of cards is . The queries must be answered online, so each query is decoded using the answer to the previous one.
Input
The first line contains two integers and ().
The next line contains integers ().
Each of the next lines contains two integers and (). Let be the answer to the previous query. Then and are the decoded query. Here is the bitwise exclusive OR. It is guaranteed that after decoding, . If no query has been answered yet, .
Output
For each query, print one line with the answer.
Hint
For the first example, the segments in the queries are , , , , and .