#P9583. 「MXOI Round 1」涂色

    ID: 10783 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 显示难度普及 上传者: 标签>模拟洛谷原创O2优化排序差分洛谷月赛

「MXOI Round 1」涂色

Problem Description

Xiao C is using colored pencils to color a grid paper with nn rows and mm columns. Initially, all cells are blank.

He will perform qq coloring operations in total. In each operation, he chooses either a row or a column, and adds 11 layer of color to every cell in that row or column.

Xiao C likes light colors, so after each operation, he will erase the color of all cells that have been colored with exactly kk layers, making those cells blank again.

Xiao C wants to know how many cells are colored in the end.

Input Format

The first line contains four integers n,m,q,kn,m,q,k.

The next qq lines each contain two integers op,xop,x.

  • If op=1op=1, it means adding 11 layer of color to all cells in row xx;
  • If op=2op=2, it means adding 11 layer of color to all cells in column xx.

Output Format

Output one integer, indicating how many cells are colored in the end.

3 4 5 3
1 3
2 4
1 2
1 3
2 2
8

Hint

[Sample Explanation #1]

The cell in row 11, column 11 is not colored; the cell in row 11, column 22 has 11 layer of color; the cell in row 11, column 33 is not colored; the cell in row 11, column 44 has 11 layer of color;

The cell in row 22, column 11 has 11 layer of color; the cell in row 22, column 22 has 22 layers of color; the cell in row 22, column 33 has 11 layer of color; the cell in row 22, column 44 has 22 layers of color;

The cell in row 33, column 11 has 22 layers of color; the color of the cell in row 33, column 22 is erased; the cell in row 33, column 33 has 22 layers of color; the color of the cell in row 33, column 44 is also erased;

In the end, a total of 88 cells are colored.

[Sample #2]

See paint/paint2.in and paint/paint2.ans in the attached files.

This sample satisfies the constraints of test points 11.

[Sample #3]

See paint/paint3.in and paint/paint3.ans in the attached files.

This sample satisfies the constraints of test points 55.

[Sample #4]

See paint/paint4.in and paint/paint4.ans in the attached files.

This sample satisfies the constraints of test points 2020.

[Constraints]

For 100%100\% of the data, 1≤n,m≤2×1051 \le n,m \le 2\times 10^5, 1≤k≤q≤5×1051 \le k \le q \le 5 \times 10^5, op∈{1,2}op \in \{1,2\}. It is guaranteed that when op=1op=1, 1≤x≤n1 \le x \le n, and when op=2op=2, 1≤x≤m1 \le x \le m.

Test point ID n,m≤n,m \le q≤q \le Special property
1∼41\sim4 30003000 30003000 None
5∼95\sim9 5×1055\times10^5
10∼1210\sim12 2×1052\times10^5 A
13∼1613\sim16 B
17∼2017\sim20 None

Special property A: It is guaranteed that op=1op=1.

Special property B: It is guaranteed that k=2k=2.

Translated by ChatGPT 5