Segment Tree Practice 4
View as PDFGiven an array  of size 
, support the 
 of the following queries:
Count the number of elements appearing exactly once in the range .
Constraints
Input Specification
The first line contains  integers 
 and 
.
The second line contains  integers 
, the elements of 
.
The next  lines each contain 
 integers 
 and 
, representing a query on the range 
.
Output Specification
For each query output one integer on its own line, the answer to that query.
Sample Input
7 5
1 2 3 2 4 3 1
2 5
1 7
4 7
3 6
1 1
Sample Output
2
1
4
2
1
Comments
Is it possible to solve this problem using bitset?
I solved it with byte set: https://dmoj.ca/src/7195549
Is it possible to solve this problem using segment tree?
Yes. You can answer all the queries offline with segment tree.