6810.Distinct Values Queries

Time Limit: 1s Memory Limit: 512MB

You are given an array of $n$ integers and $q$ queries of the form: how many distinct values are there in a range $[a,b]$ ?

Input Format(From the terminal/stdin)

The first input line has two integers $n$ and $q$ : the array size and number of queries.

The next line has $n$ integers $x_1,x_2,\dots,x_n$ : the array values.

Finally, there are $q$ lines describing the queries. Each line has two integers $a$ and $b$ .

  • $1 \le n,q \le 2 \cdot 10^5$
  • $1 \le x_i \le 10^9$
  • $1 \le a \le b \le n$

Output Format(To the terminal/stdout)

For each query, print the number of distinct values in the range.

Sample Input

Copy
5 3
3 2 3 1 2
1 3
2 4
1 5
 · \n
 · · · · \n
 · \n
 · \n
 · \n

Sample Output

Copy
2
3
3
 \n
 \n
 \n
Source: CSES, Range Queries, 1734

Submit

请先 登录

© 2025 FAQs