#abc370d. D - Cross Explosion
D - Cross Explosion
Score : points
问题陈述
有一个 行 列的网格。用 表示从顶部数第 行,从左边数第 列的单元格。 最初,每个单元格中都有一堵墙。 在按照给定顺序处理了 个查询后,找出剩余的墙的数量。
在第 个查询中,你将得到两个整数 和 。 你在 放置一个炸弹来摧毁墙。结果,会发生以下过程。
- 如果 处有墙,摧毁那堵墙并结束过程。
- 如果 处没有墙,摧毁从 向上、向下、向左和向右看时首次出现的墙。更准确地说,同时发生以下四个过程:
- 如果存在一个 使得 处有墙,并且对于所有 , 处没有墙,摧毁 处的墙。
- 如果存在一个 使得 处有墙,并且对于所有 , 处没有墙,摧毁 处的墙。
- 如果存在一个 使得 处有墙,并且对于所有 , 处没有墙,摧毁 处的墙。
- 如果存在一个 使得 处有墙,并且对于所有 , 处没有墙,摧毁 处的墙。
以上为大语言模型 kimi 翻译,仅供参考。
Problem Statement
There is a grid with rows and columns. Let denote the cell at the -th row from the top and -th column from the left.
Initially, there is one wall in each cell.
After processing queries explained below in the order they are given, find the number of remaining walls.
In the -th query, you are given two integers and .
You place a bomb at to destroy walls. As a result, the following process occurs.
- If there is a wall at , destroy that wall and end the process.
- If there is no wall at , destroy the first walls that appear when looking up, down, left, and right from . More precisely, the following four processes occur simultaneously:
- If there exists an such that a wall exists at and no wall exists at for all , destroy the wall at .
- If there exists an such that a wall exists at and no wall exists at for all , destroy the wall at .
- If there exists a such that a wall exists at and no wall exists at for all , destroy the wall at .
- If there exists a such that a wall exists at and no wall exists at for all , destroy the wall at .
Constraints
- All input values are integers.
Input
The input is given from Standard Input in the following format:
Output
Print the number of remaining walls after processing all queries.
Sample Input 1
2 4 3
1 2
1 2
1 3
Sample Output 1
2
The process of handling the queries can be explained as follows:
- In the 1st query, . There is a wall at , so the wall at is destroyed.
- In the 2nd query, . There is no wall at , so the walls at , which are the first walls that appear when looking up, down, left, and right from , are destroyed.
- In the 3rd query, . There is no wall at , so the walls at , which are the first walls that appear when looking up, down, left, and right from , are destroyed.
After processing all queries, there are two remaining walls, at and .
Sample Input 2
5 5 5
3 3
3 3
3 2
2 2
1 2
Sample Output 2
10
Sample Input 3
4 3 10
2 2
4 1
1 1
4 2
2 1
3 1
1 3
1 2
4 3
4 2
Sample Output 3
2