시간 제한메모리 제한제출정답맞힌 사람정답 비율
3 초 2048 MB432100.000%

문제

Randias is playing a card game. In this game, each card has a number written on it. For cards with numbers $a_{1}, a_{2}, \ldots, a_{m}$, 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 $i$-th operation, Randias will put the $i$-th card (this card has number $a_{i}$ written on it) at the end of the card sequence. Then:

  • If there are no other cards in the sequence with number $a_{i}$ written on them, the $i$-th operation ends.
  • Otherwise, let the $j$-th card in the card sequence have number $a_{i}$ written on it. Randias will take away all cards between the $j$-th card and the newly placed card, including the $j$-th card and the newly placed card.

For example, let $a = [2, 1, 3, 1, 2, 3]$, and the card sequence $s = []$ initially.

After the $1$-st operation, $s = [2]$.

After the $2$-nd operation, $s = [2, 1]$.

After the $3$-rd operation, $s = [2, 1, 3]$.

After the $4$-th operation, $s = [2]$ (cards $1, 3, 1$ are taken away).

After the $5$-th operation, $s = []$ (cards $2, 2$ are taken away).

After the $6$-th operation, $s = [3]$.

Now, Randias is given $n$ cards $a_{1}, a_{2}, \ldots, a_{n}$. He has $q$ queries. The $i$-th query is a pair of integers $\ell_{i}, r_{i}$. With this query, Randias wants to know how many cards will be left in the card sequence if the initial list of cards is $a_{\ell_{i}}, a_{\ell_{i} + 1}, \ldots, a_{r_{i}}$.

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 $n$ and $q$ ($1 \le n, q \le 3 \cdot 10^5$) denoting the number of cards and the number of queries.

The following line contains $n$ integers $a_{1}, a_{2}, \ldots, a_{n}$ ($1 \le a_{i} \le n$).

Each of the following $q$ lines contains two integers $\ell'_{i}$ and $r'_{i}$ ($0 \le \ell'_{i} ,r'_{i} \le 2n$). Let the answer for the last query is $\mathit{lastans}$. Then $\ell_{i} = \ell'_{i} \oplus \mathit{lastans}$ and $r_{i} = r'_{i} \oplus \mathit{lastans}$ are the next query. In these formulas, $\oplus$ is the bitwise exclusive OR operation. It is guaranteed that, after decoding, $1 \le \ell_{i} \le r_{i} \le n$. If you haven't answered any queries before, $\mathit{lastans} = 0$.

출력

For each query, output a line with one integer: the answer to that query.

예제 입력 1

5 5
3 3 1 1 1
5 5
3 4
3 3
0 5
3 5

예제 출력 1

1
2
1
0
1

예제 입력 2

7 7
2 4 1 2 3 1 2
1 6
0 4
3 3
0 4
0 3
0 6
2 7

예제 출력 2

2
1
1
1
2
3
0

노트

For the first example, the segments in the queries are $[5, 5]$, $[2, 5]$, $[1, 1]$, $[1, 4]$, and $[3, 5]$.