[USACO 2016 Dec S]Counting Haybales
题号:NC24117
时间限制:C/C++/Rust/Pascal 1秒,其他语言2秒
空间限制:C/C++/Rust/Pascal 256 M,其他语言512 M
64bit IO Format: %lld

题目描述

Farmer John has just arranged his N haybales (1≤N≤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 Q queries (1≤Q≤100,000), each asking for the number of haybales within a specific interval along the road.

输入描述:

The first line contains N and Q.
The next line contains N distinct integers, each in the range 0…1,000,000,000, indicating that there is a haybale at each of those locations.

Each of the next Q lines contains two integers A and B (0≤A≤B≤1,000,000,000) giving a query for the number of haybales between A and B, inclusive.

输出描述:

You should write Q lines of output. For each query, output the number of haybales in its respective interval.
示例1

输入

复制
4 6
3 2 7 5
2 3
2 4
2 5
2 7
4 6
8 10

输出

复制
2
2
3
4
1
0