electicode
HomeCoursesResourcesProblemsNational OlympiadContestsLeaderboard
...

Count in Range

Time Limit: 1000msMemory Limit: 256MB
View Submissions

Problem Description

An array aaa of nnn integers a1,a2,…,ana_1, a_2, \dots, a_na1​,a2​,…,an​ is given. It is necessary to answer queries of the form: «How many numbers in the array have values from lll to rrr inclusive?».

Input Format

The first line contains an integer nnn (1≤n≤105)(1 \le n \le 10^5)(1≤n≤105) --- the length of the array.

The second line contains nnn integers a1,a2,…,ana_1, a_2, \dots, a_na1​,a2​,…,an​ --- the elements of the array.

The third line contains an integer kkk (1≤k≤105)(1 \le k \le 10^5)(1≤k≤105) --- the number of queries.

Then follow kkk lines, each of which contains two integers lll and rrr (−109≤l≤r≤109)(−10^9 \le l \le r \le 10^9)(−109≤l≤r≤ --- the bounds of the next query.

Output Format

For each query output one number --- the answer to it. Print all answers one per line.

Examples

Example 1
Input
5
7 1 8 10 5
6
2 100
4 7
1 9
1 10
2 4
9 9
Output
4
2
4
5
0
0

© 2026 Electicode. All rights reserved.

(−109≤ai≤109)(−10^9 \le a_i \le 10^9)
(−109≤ai​≤109)
1
09
)