#FT0000199. Sơn lưới theo hàng và cột (E-liter)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Sơn lưới theo hàng và cột (E-liter)
E-liter
Source: AtCoder
Version: Phuoc Hung OJ Extended
Problem Statement
Initially, an grid contains only white cells. Rows are numbered from to from top to bottom, and columns from to from left to right.
Process operations in their given order. An operation is one of the following:
1 R: Paint every cell in row black, regardless of its current color.2 C: Paint every cell in column white, regardless of its current color.
Operations modify the current grid and may paint the same row or column repeatedly. A cell's current color is determined by the most recent operation that affected it.
After each operation, determine the number of black cells in the entire grid.
Input
- The first line contains two integers , the grid size and the number of operations.
- Each of the next lines contains
1 Ror2 C, giving the operation type and the corresponding row or column index. - Operations are applied in the order in which they appear.
Output
Print exactly lines. Line contains the number of black cells immediately after operation . The count can be as large as , so a sufficiently wide integer type is required.
Subtasks
- Subtask 1 (20 points): ; ;
1 Ralways has ;2 Calways has . - Subtask 2 (30 points): ; ;
1 Ralways has ;2 Calways has . - Subtask 3 (50 points): ; ;
1 Ralways has ;2 Calways has .
Examples
Example 1
Input
3 4
1 1
1 3
2 2
1 1
Output
3
6
4
5
Explanation
The grid is initially white. Painting row 1 makes cells black. Painting row 3 adds , bringing the total to . Painting column 2 white removes two black cells, one from each painted row, leaving . Repainting row 1 turns cell black again while the other two cells in that row are already black, so the total becomes . Thus the outputs are 3, 6, 4, and 5.
Example 2
Input
300000 1
2 300000
Output
0
Explanation
All cells of the grid are initially white. Painting column white changes no cell, so the number of black cells remains .