#P16491. [GKS 2014 #D] GBus count

    ID: 16476 Type: RemoteJudge 1000ms 1024MiB Tried: 0 Accepted: 0 Difficulty: 3 Uploaded By: Tags>2014前缀和差分Google Kick Start

[GKS 2014 #D] GBus count

题目描述

There exist some cities that are built along a straight road. The cities are numbered 11, 22, 33... from left to right.

There are NN GBuses that operate along this road. For each GBus, we know the range of cities that it serves: the i-th gBus serves the cities with numbers between AiA_i and BiB_i, inclusive.

We are interested in a particular subset of PP cities. For each of those cities, we need to find out how many GBuses serve that particular city.

输入格式

The first line of the input gives the number of test cases, TT. Then, TT test cases follow; each case is separated from the next by one blank line. (Notice that this is unusual for Kickstart data sets.)

In each test case:

  • The first line contains one integer NN: the number of GBuses.
  • The second line contains 2N2N integers representing the ranges of cities that the buses serve, in the form A1 B1 A2 B2 A3 B3AN BNA_1 \ B_1 \ A_2 \ B_2 \ A_3 \ B_3 \dots A_N \ B_N. That is, the first GBus serves the cities numbered from A1A_1 to B1B_1 (inclusive), and so on.
  • The third line contains one integer PP: the number of cities we are interested in, as described above. (Note that this is not necessarily the same as the total number of cities in the problem, which is not given.)
  • Finally, there are PP more lines; the i-th of these contains the number CiC_i of a city we are interested in.

输出格式

For each test case, output one line containing Case #x: y, where xx is the number of the test case (starting from 11), and yy is a list of PP integers, in which the i-th integer is the number of GBuses that serve city CiC_i.

2
4
15 25 30 35 45 50 10 20
2
15
25
10
10 15 5 12 40 55 1 10 25 35 45
50 20 28 27 35 15 40 4 5
3
5
10
27
Case #1: 2 1
Case #2: 3 3 4

提示

In Sample Case #1, there are four GBuses. The first serves cities 1515 through 2525, the second serves cities 3030 through 3535, the third serves cities 4545 through 5050, and the fourth serves cities 1010 through 2020. City 1515 is served by the first and fourth buses, so the first number in our answer list is 22. City 2525 is served by only the first bus, so the second number in our answer list is 11.

Limits

1T101 \le T \le 10.

Small dataset (Test Set 1 - Visible)

1N501 \le N \le 50

1Ai5001 \le A_i \le 500, for all ii.

1Bi5001 \le B_i \le 500, for all ii.

1Ci5001 \le C_i \le 500, for all ii.

1P501 \le P \le 50.

Large dataset (Test Set 2 - Hidden)

1N5001 \le N \le 500.

1Ai50001 \le A_i \le 5000, for all ii.

1Bi50001 \le B_i \le 5000, for all ii.

1Ci50001 \le C_i \le 5000, for all ii.

1P5001 \le P \le 500.