Problem list
Log in
#r03105 · Online Judge > GoldOJ

Count Values in a Range

Silver IV 2.0 s 256 MB

A sorted sequence of $n$ integers (duplicates allowed) is given. For each of $k$ queries $a$, $b$, print how many elements lie in $[a, b]$ (inclusive).

Input

Line 1: $n$. Line 2: $n$ sorted integers. Line 3: $k$. Next $k$ lines: $a$ $b$.

Output

Print the count for each query, one per line.

Example 1

Input
5
1 2 3 4 5
3
1 2
2 4
5 6
Output
2
3
1
Source
Online Judge > GoldOJ
Appears in
Not part of a ladder, contest or set yet.
Accepted 0 Submissions 0 Acceptance 0% Solvers 0

Discussion

Threads about this problem. Spoilers are collapsed; wrap hints in ||double bars||.

No discussion yet. Start a thread if something here needs explaining.

Recent submissions Open with filters
Code