QOJ.ac

QOJ

Time Limit: 2 s Memory Limit: 512 MB Total points: 100

#10143. Pinball

الإحصائيات

— Calm yourselves a little...

We have a ball which lies on the $X$ axis, initially placed at the $0$ coordinate. We also have $N$ sets of walls which lie on the $X$ axis. Each set is described as a tuple $(dir,len,freq)$ where:

  • $dir$ indicates the direction in which the walls are placed, which can either be L (left) or R (right)
  • if $dir=$ L, then the walls in the set are placed at $−len$, $−2 \cdot len$, $−3 \cdot len$, ..., $−freq \cdot len$
  • if $dir=$ R, then the walls in the set are placed at $len$, $2 \cdot len$, $3 \cdot len$, ..., $freq \cdot len$

Note that through the nature of these informations, there can be multiple walls placed at the same coordinate.

At time $T=0$ the ball starts moving to the right with a constant speed of one unit per second. When the ball hits a wall, the wall is automatically destroyed and the ball reverses its direction. If there are multiple walls situated at the same coordinate, only one of the walls is destroyed.

Task

You are given $Q$ queries. For each query you are given an integer $T$. Output the coordinate of the ball after $T$ seconds.

Input data

The first line of input will contain the integers $N$ and $Q$, separated by one space.

The next $N$ lines contain three space-separated integers, $dir$, $len$ and $freq$, describing how the walls are placed.

The next $Q$ lines contain an integer, $T$, describing a query.

Output data

Output $Q$ lines, the $i$−th line should contain the answer for $i$−th query.

Constraints and clarifications

  • $1 \leq N, Q \leq 250 \ 000$
  • $1 \leq T \leq 10^{12}$
  • $dir \in \{$L$,$ R$\}$
  • $1 \leq len, freq \leq 10^{12}$
# Points Constraints
0 0 Examples
1 13 $N, Q \leq 1 \ 000$
2 8 $Q, T \leq 1 \ 000$
3 16 $1 \leq len \leq 10$
4 10 $T \leq 10^6$
5 11 $len \cdot freq \leq 10^6$
6 9 Let $S$ be the sum of all $freq$ in the input. $S \leq 10^6$
7 33 No additional constraints

Example

stdin

3 12
R 3 2
R 6 1
L 3 2
0
1
2
3
4
5
6
7
17
18
19
200

stdout

0
1
2
3
2
1
0
-1
5
6
5
-152
About Issues

We understand that our problem archive is not perfect. If you find any issues with the problem, including the statement, scoring configuration, time/memory limits, test cases, etc.

You may use this form to submit an issue regarding the problem. A problem moderator will review your issue and proceed it properly.

STOP! Before you submit an issue, please READ the following guidelines:

  1. This is not a place to publish a discussion, editorial, or requests to debug your code. Your issue will only be visible by you and problem moderators. Other users will not be able to view or reply your issues.
  2. Do not submit duplicated issues. If you have already submitted one, please wait for an moderator to review it. Submitting multiple issues will not speed up the review process and might cause your account to be banned.
  3. Issues must be filed in English or Chinese only.
  4. Be sure your issue is related to this problem. If you need to submit an issue regarding another problem, contest, category, etc., you should submit it to the corresponding page.

Active Issues 0

No issues in this category.

Closed/Resolved Issues 0

No issues in this category.