~/algor $ cat problems/qidiruv-oraliqdagi-sonlar
Numbers in a range
Medium
1000 ms
128 MB
49%
An array $a$ of $n$ integers (not sorted) and $q$ queries are given. Each query gives two integers $l$ and $r$: how many elements of the array satisfy $l \le a_{i} \le r$?
Input
The first line contains two positive integers: $n$ and $q$. The second line contains $n$ integers $a_{i}$ separated by spaces. Each of the next $q$ lines contains two integers: $l$ and $r$.
Output
$q$ lines: for each query one integer — the number of elements satisfying the condition.
Note
$1 \le n, q \le 10^{5}$
$-10^{9} \le a_{i} \le 10^{9}$
$-10^{9} \le l \le r \le 10^{9}$
Examples
Input #1
6 3 5 1 9 3 7 3 2 5 3 3 10 20
Output #1
3 2 0
Input #2
3 2 -5 0 5 -5 5 1 4
Output #2
3 0