#P15760. [JAG 2025 Summer Camp #1] Path Flipping

[JAG 2025 Summer Camp #1] Path Flipping

题目描述

For a grid with each cell colored either white or black, let us define the beauty of the grid as follows:

  • Consider performing the following operation any number of times:
    • Choose a path from the upper-left corner to the lower-right corner, consisting only of downward and rightward moves. Invert the colors of all cells on the chosen path.
  • The beauty of the grid is defined as the maximum possible number of cells colored black.

You have a grid with HH rows and WW columns. Initially, all cells are colored white.

You need to process QQ queries in order. The ii-th query is given in the following format:

  • You are given two integers tit_i and xix_i.
    • If ti=1t_i = 1, invert the colors of all cells in the xix_i-th row from the top.
    • If ti=2t_i = 2, invert the colors of all cells in the xix_i-th column from the left.
  • Then, find the beauty of the current grid.

输入格式

The input is given in the following format:

$$\begin{aligned} & H \ W \ Q \\ & t_1 \ x_1 \\ & \vdots \\ & t_Q \ x_Q \end{aligned}$$
  • 1H,W200 0001 \leq H, W \leq 200\ 000
  • 1Q200 0001 \leq Q \leq 200\ 000
  • ti{1,2}t_i \in \{1, 2\} (1iQ1 \leq i \leq Q)
  • ti=1    1xiHt_i = 1 \implies 1 \leq x_i \leq H (1iQ1 \leq i \leq Q)
  • ti=2    1xiWt_i = 2 \implies 1 \leq x_i \leq W (1iQ1 \leq i \leq Q)
  • All input values are integers.

输出格式

Output QQ lines. On the ii-th line (1iQ1 \leq i \leq Q), output the answer for the ii-th query.

3 4 5
2 2
2 3
1 1
1 2
2 3
9
12
10
10
9