QOJ.ac

QOJ

Time Limit: 4.0 s Memory Limit: 512 MB Total points: 100 Hackable ✓

#10893. 围墙游戏

Statistics

最近,Grammy 正在玩一个名为“墙壁游戏”(Wall Game)的无聊游戏。

游戏中的平面由正六边形铺满。平面上有蜂巢,它们的排列方式使得上下方有六边形节点,左右两侧有蜂巢与同行的相邻蜂巢共享边。每一行相对于前一行偏移了半个蜂巢的距离。$Ox$ 轴沿着水平的蜂巢行从左向右延伸。$Oy$ 轴相对于 $Ox$ 轴倾斜 60 度。坐标轴在坐标为 $(0, 0)$ 的蜂巢处相交。

游戏包含两种操作:攻击和查询。通过攻击操作,Grammy 可以占领位于 $(x_i, y_i)$ 的蜂巢。对于查询操作,Grammy 想知道,如果她在她已占领的蜂巢和未占领的蜂巢之间筑起墙壁,那么当她从她领地内的蜂巢 $(x_i, y_i)$ 出发,且不跨越任何墙壁时,她能接触到多少面墙壁。

注意:当且仅当蜂巢 $A$ 和 $B$ 共享一条公共边,或者存在一个蜂巢 $C$ 使得 $A$ 可以到达 $C$ 且 $C$ 也可以到达 $B$ 时,一个人可以在蜂巢 $A$ 和 $B$ 之间移动。

游戏开始时,没有任何蜂巢被占领。请编写一个程序来处理 $n$ 次操作。

输入格式

输入仅包含一组数据。

第一行包含一个整数 $n$ ($1 \le n \le 500\,000$),表示操作次数。

接下来的 $n$ 行描述了 $n$ 次操作。每行包含 3 个整数 $op_i, x_i$ 和 $y_i$ ($1 \le op_i \le 2, -10^9 \le x_i, y_i \le 10^9$),分别表示操作类型和蜂巢的坐标。

  • $op_i = 1$ 表示攻击操作。Grammy 将占领蜂巢 $(x_i, y_i)$。
  • $op_i = 2$ 表示查询操作。在此操作中,Grammy 询问你,如果她从蜂巢 $(x_i, y_i)$ 出发且不跨越任何墙壁,她能接触到多少面墙壁。

保证如果 $op_i = 1$,则 $(x_i, y_i)$ 尚未被占领;如果 $op_i = 2$,则 $(x_i, y_i)$ 已经被占领。

输出格式

对于每次查询操作,你应该输出一个整数,表示 Grammy 查询的答案。

样例

输入 1

8
1 0 0
2 0 0
1 0 2
1 1 2
1 0 3
2 0 3
1 0 1
2 0 0

输出 1

6
12
20

Figure 1. 蜂巢坐标系示意图

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.