Problem11256--[yosupo] Data Structure - Static Range Count Distinct

11256: [yosupo] Data Structure - Static Range Count Distinct

[Creator : ]
Time Limit : 1.000 sec  Memory Limit : 512 MiB

Description

You are given an integer sequence $a_0, a_1, \ldots, a_{N-1}$ with the length $N$. Process the following $Q$ queries in order:

- $l$ $r$ : Print the number of distinct integers that occur in $a_{l}, a_{l+1}, \ldots, a_{r-1}$.

Input

$N$ $Q$
$a_0$ $a_1$ $\cdots$ $a_{N-1}$
$l_0$ $r_0$
$l_1$ $r_1$
$\vdots$
$l_{Q-1}$ $r_{Q-1}$

Constraints

- $0 \leq N \leq 5\times 10^5$
- $0 \leq Q \leq 5\times 10^5$
- $0 \leq a_i \leq 10^9$
- $0 \leq l \leq r \leq N$

Sample 1 Input

5 3
3 7 1 2 1
1 5
3 3
0 4

Sample 1 Output

3
0
4

HINT

Yosupo.

Source/Category