Segment Tree Practice 4

View as PDF

Submit solution

Points: 17
Time limit: 0.6s
Memory limit: 256M

Author:
Problem type

Given an array A of size N, support the Q of the following queries:

Count the number of elements appearing exactly once in the range [l,r].

Constraints

1N,Q2×105

1lrN

1AiN

Input Specification

The first line contains 2 integers N and Q.

The second line contains N integers A1,A2,,AN, the elements of A.

The next Q lines each contain 2 integers li and ri, representing a query on the range [li,ri].

Output Specification

For each query output one integer on its own line, the answer to that query.

Sample Input

Copy
7 5
1 2 3 2 4 3 1
2 5
1 7
4 7
3 6
1 1

Sample Output

Copy
2
1
4
2
1

Comments

There are no comments at the moment.