Item Acquired
English
Language
Contribute a translation- Time limit
- 3000 ms
- Memory limit
- 1024 MB
- Submissions
- 0
- Correct
- 0
- Solved by
- 0
- AC rate
- —
Statement
You are building a game that obtains items by driving a car in a 2D map.
There are $N$ boxes on the map from which items can be obtained. The position of the $i$-th box is located at $(x_i, y_i)$, and every time the car passes through this location, it can obtain $w_i$ items.
The car moves in a direction parallel to either the x-axis or the y-axis. Each movement of the car can be presented as $d$ and $v$. If $d=0$, the car moves $v$ units in the direction of increasing x-coordinate; if $d=1$, the car moves $v$ units in the direction of increasing y-coordinate; if $d=2$, the car moves $v$ units in the direction of decreasing x-coordinate; if $d=3$, the car moves $v$ units in the direction of decreasing y-coordinate.
In this case, the items from a box located at the starting position of the movement cannot be obtained. In other words, when moving from $(s_x, s_y)$ to $(e_x, e_y)$, the items from the box at $(s_x, s_y)$ cannot be obtained, while the item at $(e_x, e_y)$ can be obtained.
The car starts at $(1, 1)$ and makes a total of $Q$ movements. Given the direction and distance of each movement, determine the total number of items obtained during the $Q$ movements.
Constraints
- $1 \le N \le 200\,000$
- $1 \le Q \le 200\,000$
- $1 \le x_i \le 200\,000$
- $1 \le y_i \le 200\,000$
- $1 \le w_i \le 200\,000$
- $0 \le d_j \le 3$
- $1 \le v_j \le 200\,000$
- The positions of the boxes are different from each other.
- At every moment, the car's x and y coordinates are between $1$ and $200\,000$, inclusive.
- All given numbers are integers.
Subtasks
- (9 points) $N \le 2\,000$, $Q \le 2\,000$, $x_i \le 1\,000$, $y_i \le 1\,000$, $w_i \le 10$, and at every moment, the car's x and y coordinates are at most $1\,000$.
- (17 points) $N \le 2\,000$, $Q \le 2\,000$, $w_i \le 10$.
- (15 points) All boxes have distinct x-coordinates and distinct y-coordinates.
- (37 points) $w_i = 1$.
- (22 points) No additional constraints.
Input
The first line contains the number of boxes $N$ and the number of moves $Q$, separated by a space.
The next $N$ lines follow. The $i$-th line contains three integers $x_i, y_i, w_i$, separated by spaces. This means that the $i$-th box is located at $(x_i, y_i)$, and each time the car passes through this position, it obtains $w_i$ items.
The next $Q$ lines follow. The $j$-th line contains two integers $d_j, v_j$, separated by a space. This means that the car moves $v_j$ units in direction $d_j$.
Output
Print the total number of items obtained during the $Q$ moves.
Examples
4 6 5 5 3 5 8 5 3 5 2 1 5 1 0 4 1 9 3 5 2 3 2 1 0 5
24
3 3 1 3 1 2 2 1 3 1 1 1 3 0 2 3 3
2
Tags
No tags yet