lightoj1088

maksyuki 发表于 oj 分类,标签:
0

1088 - Points in Segments

For example if the points are 1, 4, 6, 8, 10. And the segment is 0 to 5. Then there are 2 points that lie in the segment.Given n points (1 dimensional) and q segments, you have to find the number of points that lie in each of the segments. A point pi will lie in a segment A B if A ≤ pi ≤ B.

Input

Input starts with an integer T (≤ 5), denoting the number of test cases.

Each case starts with a line containing two integers n (1 ≤ n ≤ 105) and q (1 ≤ q ≤ 50000). The next line contains n space separated integers denoting the points in ascending order. All the integers are distinct and each of them range in [0, 108].

Each of the next q lines contains two integers Ak Bk (0 ≤ Ak ≤ Bk ≤ 108) denoting a segment.

Output

For each case, print the case number in a single line. Then for each segment, print the number of points that lie in that segment.

Sample Input

Output for Sample Input

15 31 4 6 8 100 5

6 10

7 100000

Case 1:232

Note

Dataset is huge, use faster I/O methods.

 

题目类型:二分法

算法分析:读入数据,然后二分求得所求区间的上下界在输入序列中的下标pos_low和pos_high,最后直接pos_high – pos_low即可