Card Game
시간 제한3초메모리 제한2048 MB
카드 배열의 각 온라인 구간 질의마다 스택처럼 카드를 제거하는 규칙을 적용했을 때 카드 수열에 남는 카드 수를 구한다.
문제
Randias is playing a card game. In this game, each card has a number written on it. For cards with numbers , Randias will play the game in the following way.
Initially, all cards are in his hand. Randias will maintain a card sequence (initially empty). In the -th operation, Randias will put the -th card (this card has number written on it) at the end of the card sequence. Then:
- If there are no other cards in the sequence with number written on them, the -th operation ends.
- Otherwise, let the -th card in the card sequence have number written on it. Randias will take away all cards between the -th card and the newly placed card, including the -th card and the newly placed card.
For example, let , and the card sequence initially.
After the -st operation, .
After the -nd operation, .
After the -rd operation, .
After the -th operation, (cards are taken away).
After the -th operation, (cards are taken away).
After the -th operation, .
Now, Randias is given cards . He has queries. The -th query is a pair of integers . With this query, Randias wants to know how many cards will be left in the card sequence if the initial list of cards is .
For some reason, Randias hopes you can answer the questions online. That is, you need to decode the next question with the answer for the previous question.
입력
The first line contains two integers and () denoting the number of cards and the number of queries.
The following line contains integers ().
Each of the following lines contains two integers and (). Let the answer for the last query is . Then and are the next query. In these formulas, is the bitwise exclusive OR operation. It is guaranteed that, after decoding, . If you haven't answered any queries before, .
출력
For each query, output a line with one integer: the answer to that query.
힌트
For the first example, the segments in the queries are , , , , and .