QOJ.ac

QOJ

時間限制: 2 s 記憶體限制: 1024 MB 總分: 100

#5555. 混沌构造

统计

Gircle 市只有一条街道,且该街道是环形的。在人们不随身携带指南针、GPS 和详细地图的年代,这非常方便,因为你只需要沿着一个方向走,就一定能到达目的地。自 Gircle 建市以来,时光流逝,土木工程师们现在对道路网络设计有了更深入的了解,大多数人也能即时获取可靠且精确的导航系统。然而,时间的流逝也影响了古老的街道表面,裂缝和坑洼越来越多。

当地政府最终决定改善这一状况,但保留城市的历史风貌与修建新街道不幸地是互斥的。由于旅游业对 Gircle 的经济至关重要,政府改善现状的唯一可行方案是在必要时翻修街道的某些路段。Gircle 的街道非常狭窄,因此某一路段的施工现场使得市民无法通过该路段,甚至无法离开或进入该路段。

作为 Gircle 建设与规划委员会 (GCPC) 的一员,你总是能及时获知 $n$ 个路段中哪一个被关闭或重新开放。自然地,市民们希望你能告诉他们,他们想要进行的行程在当前是否可行。

图 C.1:样例输入中查询 “? 9 7” 的示意图。

输入格式

输入包含: 一行,包含两个整数 $n$ ($2 \le n \le 10^5$) 和 $q$ ($1 \le q \le 10^5$),分别表示路段数量和事件数量。初始时没有路段关闭。 $q$ 行,每行描述一个事件。每个事件通过以下方式之一描述: “- a”:路段 $a$ ($1 \le a \le n$) 被关闭。保证路段 $a$ 此前是开放的。 “+ a”:路段 $a$ ($1 \le a \le n$) 重新开放。保证路段 $a$ 此前是关闭的。 * “? a b”:询问是否可以从路段 $a$ 前往路段 $b$ ($1 \le a, b \le n$ 且 $a \neq b$)。

输出格式

对于每个形式为 “? a b” 的事件,如果可以从路段 $a$ 移动到路段 $b$,则输出一行 “possible”,否则输出 “impossible”。如果 $a$ 或 $b$ 当前处于关闭状态,则答案为 “impossible”。

样例

输入 1

10 12
? 1 5
- 2
- 8
? 9 2
? 9 8
? 9 7
? 6 7
? 3 7
? 1 9
? 9 1
+ 8
? 10 3

输出 1

possible
impossible
impossible
impossible
possible
possible
possible
possible
possible

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.