Amplitude's latest feature request is for frequency queries. More specifically, a customer has different users.
User
has performed a certain event
times. This customer wishes to know how many customers have performed
the event between
and
times. Your job is to implement support for frequency queries!
Constraints
Subtask 1 [1 point]
Subtask 2 [1 point]
No additional constraints.
Input Specification
The first line of input contains two positive integers, and
.
The next line contains nonnegative integers. The
th integer,
, is the number of times
user
performed the event.
Each of the next lines contains two integers,
and
. This represents a single frequency query,
and the customer wants to know how many users performed the event between
and
times, inclusive.
Output Specification
Output lines. On the
th line, output the answer to the
th frequency query.
Sample Input
3 10
0 1 3
0 0
0 1
0 2
0 3
1 1
1 2
1 3
2 2
2 3
3 3
Sample Output
1
2
2
3
1
1
2
0
1
1
Sample Explanation
There are three users. One has performed the event zero times, one has performed the event once, and one has performed the event three times. Over all the frequency queries, the only one that returns zero is the one asking for how many users have performed the event exactly twice.
Comments