Under construction

Still being built. Things may change

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 a1,a2,…,ama_{1}, a_{2}, \ldots, a_{m}, Randias plays the game as follows.

Initially, all cards are in his hand. Randias maintains a card sequence, which starts empty. In the ii-th operation, he puts the ii-th card (number aia_{i}) at the end of the sequence. Then:

  • If no other card in the sequence has the number aia_{i}, the ii-th operation ends.
  • Otherwise, let the jj-th card in the sequence have the number aia_{i}. Randias takes away all cards from the jj-th card through the newly placed card, inclusive.

For example, let a=[2,1,3,1,2,3]a = [2, 1, 3, 1, 2, 3] and let the card sequence s=[]s = [] initially. After operation 1, s=[2]s = [2]. After operation 2, s=[2,1]s = [2, 1]. After operation 3, s=[2,1,3]s = [2, 1, 3]. After operation 4, s=[2]s = [2] (cards 1, 3, 1 are taken away). After operation 5, s=[]s = [] (cards 2, 2 are taken away). After operation 6, s=[3]s = [3].

Randias is given nn cards a1,a2,…,ana_{1}, a_{2}, \ldots, a_{n} and qq queries. The ii-th query is a pair ℓi,ri\ell_i, r_i. For each query, find how many cards remain in the sequence if the initial list of cards is aℓi,aℓi+1,…,aria_{\ell_i}, a_{\ell_i+1}, \ldots, a_{r_i}. 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 nn and qq (1≤n,q≤3⋅1051 \le n, q \le 3 \cdot 10^5).

The next line contains nn integers a1,a2,…,ana_{1}, a_{2}, \ldots, a_{n} (1≤ai≤n1 \le a_{i} \le n).

Each of the next qq lines contains two integers ℓi′\ell'_i and ri′r'_i (0≤ℓi′,ri′≤2n0 \le \ell'_i, r'_i \le 2n). Let lastanslastans be the answer to the previous query. Then ℓi=ℓi′⊕lastans\ell_i = \ell'_i \oplus lastans and ri=ri′⊕lastansr_i = r'_i \oplus lastans are the decoded query. Here ⊕\oplus is the bitwise exclusive OR. It is guaranteed that after decoding, 1≤ℓi≤ri≤n1 \le \ell_i \le r_i \le n. If no query has been answered yet, lastans=0lastans = 0.

Output

For each query, print one line with the answer.

Hint

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

Examples2

  1. Example 1

    Input
    5 5
    3 3 1 1 1
    5 5
    3 4
    3 3
    0 5
    3 5
    
    Expected output
    1
    2
    1
    0
    1
    
  2. Example 2

    Input
    7 7
    2 4 1 2 3 1 2
    1 6
    0 4
    3 3
    0 4
    0 3
    0 6
    2 7
    
    Expected output
    2
    1
    1
    1
    2
    3
    0