QOJ.ac

QOJ

时间限制: 4 s 内存限制: 2048 MB 总分: 100

#7661. 日本彩票

统计

Amida-kuji 是一种在日本很流行的抽奖游戏,可以用来将 $w$ 个奖品分配给 $w$ 个人。该游戏由 $w$ 条垂直线(称为“腿”)和一些连接相邻腿的水平横杆组成。腿的顶部是 $w$ 个人的起始位置,奖品位于腿的底部。要确定第 $i$ 个人的奖品,需要从顶部开始沿第 $i$ 条腿向下移动,每遇到一根横杆就切换到另一条腿。你可以通过图 J.1 看到这样的游戏以及如何追踪路径。

图 J.1:Amida-kuji 游戏示意图。第一个人连接到了第三个奖品。这也是添加所有连接且未移除任何连接时的样例输入 2。为了将第 $i$ 个人连接到第 $i$ 个奖品,只需移除腿 2 和腿 3 之间的两条横杆,以及腿 3 和腿 4 之间最上方的一根横杆。这是唯一的最小解。

你希望通过移除一些横杆来操纵抽奖,使得对于每个 $i$,第 $i$ 个人都能获得第 $i$ 个奖品。由于你不想被发现,你希望移除尽可能少的横杆。

对于本题,初始游戏配置中没有任何横杆。随后,横杆会被逐一添加或移除。在每次更改后,你需要求出为了使每个人 $i$ 都能获得第 $i$ 个奖品,最少需要移除多少根横杆。注意,通过移除所有横杆,这总是可以实现的。

输入格式

输入包含: 一行,包含三个整数 $w, h$ 和 $q$ ($2 \le w \le 20, 1 \le h, q \le 2 \cdot 10^5$),分别表示腿的数量、腿的高度和更改次数。 $q$ 行,每行包含三个整数 $y, x_1$ 和 $x_2$ ($1 \le y \le h, 1 \le x_1, x_2 \le w$),描述了一次在高度 $y$ 处、腿 $x_1$ 和 $x_2$ 之间添加或移除横杆的更改。如果该位置已经有横杆,它将被移除;否则,将添加该横杆。保证这两条腿是相邻的,即 $|x_1 - x_2| = 1$。 保证在任何时刻,所有横杆的高度各不相同。

输出格式

在每次更改后,输出一个整数,表示在当前存在的横杆配置下,为了使每个人 $i$ 都能获得第 $i$ 个奖品,最少需要移除的横杆数量。

样例

样例输入 1

4 6 7
1 1 2
2 3 4
4 3 4
5 1 2
6 3 4
3 2 3
6 3 4

样例输出 1

1
2
1
0
1
2
1

样例输入 2

5 9 12
1 3 4
2 1 2
3 2 3
4 4 5
5 2 1
6 4 3
7 2 3
8 4 3
9 4 5
6 4 3
7 2 3
1 3 4

样例输出 2

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

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.