P3407 Stroll
Description
On a road, positions are represented by integers $A$.
When $A=0$, there is a royal palace. If $A>0$, it means $A$ meters to the east of the palace; if $A
Input Format
The first line contains $3$ integers $N, T, Q$.
The next $N$ lines each contain two integers $A_i, R_i$. $A_i$ is the home coordinate. If $R_i$ is $1$, the person walks east; if it is $2$, the person walks west. It is guaranteed that the $A_i$ are in strictly increasing order and no two people share the same initial position.
The next $Q$ lines each contain one integer: the index of a person of interest (indexed $1$ to $N$ from west to east).
Output Format
Output $Q$ lines. Each line contains one integer, the coordinate of that person.
Explanation/Hint
$20\%$ of the testdata: $N \le 100$, $T \le 10000$.
Another $20\%$ of the testdata: $N \le 5000$.
Another $20\%$ of the testdata: starting from the westernmost, some consecutive citizens all walk east, and the remaining citizens all walk west.
$100\%$ of the testdata: $A_i$ are even, $|A_i| \le 10^{18}$, $|T| \le 10^{18}$, $1 \le Q \le N \le 100000$.
Translated by ChatGPT 5