#695
Unrated
2D Conveyor Belt
시간 제한
2s
메모리 제한
1024MB
제출
0
정답
0
맞힌 사람
0
정답 비율
0.0%

문제

Farmer John's milk factory can be described by an NN by NN (1N10001 \le N \le 1000) grid of cells that contain conveyor belts. Position (a,ba,b) describes the cell that is in the aa-th row from the top and bb-th column from the left. There are 55 types of cells:

"L" — the cell is a leftward facing conveyor belt which moves all items on it 1 cell left every time unit. "R" — the cell is a rightward facing conveyor belt which moves all items on it 1 cell right every time unit."U" — the cell is an upward facing conveyor belt which moves all items on it 1 cell up every time unit."D" — the cell is a downward facing conveyor belt which moves all items on it 1 cell down every time unit."?" — Farmer John has not built a conveyor belt at that cell yet.

Note that conveyor belts can also move items outside the grid. A cell cc is unusable if an item placed at cell cc 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 QQ (1Q21051 \le Q \le 2 \cdot 10^5) days starting from day 11 and ending at day QQ, Farmer John will choose a cell that does not have a conveyor belt and build a conveyor belt at the cell.

Specifically, during the ii-th day, Farmer John will build a conveyor belt of type tit_i (tiL,R,U,Dt_i \in {\text{{L,R,U,D}}}) at position (ri,cir_i,c_i) (1ri,ciN1 \le r_i,c_i \le N). It is guaranteed that there is no conveyor belt at position (ri,cir_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 NN and QQ.

The ii-th of the next QQ lines contains rir_i, cic_i, and tit_i in that order.

출력

QQ lines, the ii-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.

예제 입력 1

3 5
1 1 R
3 3 L
3 2 D
1 2 L
2 1 U

예제 출력 1

0
0
0
2
3

예제 입력 2

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

예제 출력 2

0
2
2
4
4
6
6
9

예제 입력 3

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

예제 출력 3

0
0
0
0
0
0
0
0
11
11
11
11
13

점수

Inputs 4-5: N10N \le 10Inputs 6-7: N40N \le 40Inputs 8-13: No additional constraints

코드 제출

코드를 제출하려면 로그인이 필요합니다.

로그인
내 제출
제출 내역이 없습니다.
맞은 사람
아직 맞은 사람이 없습니다.
난이도 투표
Unrated0명 투표
로그인 후 AC 받으면 투표할 수 있습니다.
전체 제출
제출 내역이 없습니다.