#P3407. 散步

散步

Description

On a road, positions are represented by integers AA.

When A=0A=0, there is a royal palace. If A>0A>0, it means AA meters to the east of the palace; if A<0A<0, it means A-A meters to the west of the palace.

Along the road, there are NN houses labeled 1N1 \sim N from west to east. Each house has exactly one person. Houses exist only at even integer points.

The king believes that the citizens’ fitness is declining and orders everyone to go out for a stroll. Every citizen can walk 11 meter per second. Each citizen walks either east or west; these directions are known to you. All citizens start their stroll simultaneously when the order is issued.

However, the citizens are very talkative. If two people meet during the stroll, they stop and talk. If a walking person reaches a point that coincides with someone who has already stopped, they will also stop and talk. Once they stop, they will chat endlessly and forget about the stroll.

Now TT seconds have passed since the order was issued. There are QQ important persons of interest, and the king wants to know their positions. Can you help him?

Input Format

The first line contains 33 integers N,T,QN, T, Q.

The next NN lines each contain two integers Ai,RiA_i, R_i. AiA_i is the home coordinate. If RiR_i is 11, the person walks east; if it is 22, the person walks west. It is guaranteed that the AiA_i are in strictly increasing order and no two people share the same initial position.

The next QQ lines each contain one integer: the index of a person of interest (indexed 11 to NN from west to east).

Output Format

Output QQ lines. Each line contains one integer, the coordinate of that person.

6 6 4
-10 1
-6 2
-4 1
2 1
6 2
18 2
2
3
4
6
-8
2
4
12

Hint

20%20\% of the testdata: N100N \le 100, T10000T \le 10000.

Another 20%20\% of the testdata: N5000N \le 5000.

Another 20%20\% of the testdata: starting from the westernmost, some consecutive citizens all walk east, and the remaining citizens all walk west.

100%100\% of the testdata: AiA_i are even, Ai1018|A_i| \le 10^{18}, T1018|T| \le 10^{18}, 1QN1000001 \le Q \le N \le 100000.

Translated by ChatGPT 5