logo AlgoBeat OnlineJudge
登录 注册

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

内存限制:1024 MiB 时间限制:2000 ms 标准输入输出
题目类型:VJudge(洛谷) 评测方式:VJudge
上传者: 匿名

题目描述

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 rows and columns. Initially, all cells are colored white.

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

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

输入格式

The input is given in the following format:

  • ()
  • ()
  • ()
  • All input values are integers.

输出格式

Output lines. On the -th line (), output the answer for the -th query.

样例

样例输入 1

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

样例输出 1

9
12
10
10
9