luogu#P3184. [USACO16DEC] Counting Haybales S

[USACO16DEC] Counting Haybales S

题目描述

Farmer John has just arranged his NN haybales (1N100,0001 \leq N \leq 100,000) at various points along the one-dimensional road running across his farm. To make sure they are spaced out appropriately, please help him answer QQ queries (1Q100,0001 \leq Q \leq 100,000), each asking for the number of haybales within a specific interval along the road.

输入格式

The first line contains NN and QQ.

The next line contains NN distinct integers, each in the range 01,000,000,0000 \ldots 1,000,000,000, indicating that there is a haybale at each of those locations.

Each of the next QQ lines contains two integers AA and BB(0AB1,000,000,0000 \leq A \leq B \leq 1,000,000,000) giving a query for the number of haybales between AA and BB, inclusive.

输出格式

You should write QQ lines of output. For each query, output the number of haybales in its respective interval.

题目大意

题目描述

Farmer John 刚刚将他的 NN 个干草捆(1N100,0001 \leq N \leq 100,000)安排在他农场的一维道路上的各个位置。为了确保它们之间的间距合适,请帮助他回答 QQ 个查询(1Q100,0001 \leq Q \leq 100,000),每个查询询问在道路的特定区间内有多少个干草捆。

输入格式

第一行包含 NNQQ

第二行包含 NN 个不同的整数,每个整数的范围在 01,000,000,0000 \ldots 1,000,000,000 之间,表示每个位置上有一个干草捆。

接下来的 QQ 行每行包含两个整数 AABB0AB1,000,000,0000 \leq A \leq B \leq 1,000,000,000),表示一个查询,询问在 AABB(包括 AABB)的区间内有多少个干草捆。

输出格式

你需要输出 QQ 行。对于每个查询,输出其对应区间内的干草捆数量。

4 6
3 2 7 5
2 3
2 4
2 5
2 7
4 6
8 10
2
2
3
4
1
0