| 시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
|---|---|---|---|---|---|
| 2 초 | 2048 MB | 145 | 81 | 68 | 62.963% |
Farmer John's milk factory can be described by an $N$ by $N$ (1ドル \le N \le 1000$) grid of cells that contain conveyor belts. Position ($a,b$) describes the cell that is in the $a$-th row from the top and $b$-th column from the left. There are 5ドル$ types of cells:
Note that conveyor belts can also move items outside the grid. A cell $c$ is unusable if an item placed at cell $c$ will never exit the conveyor belt grid (i.e. it will move around in the grid forever).
Initially, Farmer John has not started building the factory so all cells start out as "?". For the next $Q$ (1ドル \le Q \le 2 \cdot 10^5$) days starting from day 1ドル$ and ending at day $Q,ドル Farmer John will choose a cell that does not have a conveyor belt and build a conveyor belt at the cell.
Specifically, during the $i$-th day, Farmer John will build a conveyor belt of type $t_i$ ($t_i \in {\text{{L,R,U,D}}}$) at position ($r_i,c_i$) (1ドル \le r_i,c_i \le N$). It is guaranteed that there is no conveyor belt at position ($r_i,c_i$).
After each day, help Farmer John find the minimum number of unusable cells he can achieve by optimally building conveyor belts on all remaining cells without a conveyor belt.
The first line contains $N$ and $Q$.
The $i$-th of the next $Q$ lines contains $r_i,ドル $c_i,ドル and $t_i$ in that order.
$Q$ lines, the $i$-th of which describing the minimum number of unusable cells if Farmer John fills optimally builds conveyor belts on all remaining cells that do not currently have a conveyor belt.
3 5 1 1 R 3 3 L 3 2 D 1 2 L 2 1 U
0 0 0 2 3
The conveyor belt after the fifth day is shown below.
RL? U?? ?DL
One optimal way to build conveyor belts on the remaining cells is as follows.
RLR URR LDL
In this configuration, the cells at (1,ドル 1$), (1,ドル 2$), and (2,ドル 1$) are unusable.
3 8 1 1 R 1 2 L 1 3 D 2 3 U 3 3 L 3 2 R 3 1 U 2 1 D
0 2 2 4 4 6 6 9
The conveyor belt after the eighth day is shown below.
RLD D?U URL
No matter what conveyor belt Farmer John can build at the center, all cells will be unusable.
4 13 2 2 R 2 3 R 2 4 D 3 4 D 4 4 L 4 3 L 4 2 U 3 1 D 4 1 R 2 1 L 1 1 D 1 4 L 1 3 D
0 0 0 0 0 0 0 0 11 11 11 11 13