300806: CF154B. Colliders

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Colliders

题意翻译

## 题目描述 在2312年,宇宙中发现了 $n$ 台巨型对撞机,这些对撞机分别用 $1 \sim n$ 的自然数标识。科学家们不知道启动这些对撞机会发生什么危险事故,所以这些机器,刚开始都是出于关闭的状态。 随着科学家们的研究发现,第 $i$ 台对撞机启动是安全的,当且仅当其他已经启动的对撞机的标识数都跟这台对撞机标识数互质。(例如假设前面启动的对撞机标识数是 $j$,如果 $i$ 能启动,那么 $i,j$ 互质,即 $\gcd(i,j) = 1$)。如果两台对撞机的标识数不为互质数就启动,那么就会发生爆炸事故。 基于前面的研究,科学家们准备做各种启动和关闭对撞机的实验。为了确保科学家们的生命安全,你要设计一个远程遥控的软件。 刚开始,所有的对撞机都是关闭状态。你的程序将会收到许多询问,格式为“启动、关闭第 $i$ 台对撞机”。这个程序应该能处理这些询问(根据收到询问的先后顺序处理)。程序按照如下的格式输出处理结果。 如果询问为 `+ i`(表示启动第 $i$ 台对撞机),程序应该按照下面三种情况之一输出结果。 - `Success`,表示启动第 $i$ 台是安全的。 - `Already on`,表示第 $i$ 台在询问之前就已经启动了。 - `Conflict with j`,表示第 $i$ 台与前面已经启动的第 $j$ 台冲突。如果前面有多台对撞机跟 $i$ 冲突,那么只输出其中任何一台即可。 如果询问为 `- i`(表示关闭第 $i$ 台对撞机),程序应该按照下面两种情况之一输出结果。 - `Success`,表示关闭第 $i$ 台对撞机。 - `Already off`,表示第 $i$ 台对撞机在询问之前就已经关闭了。 ## 输入格式 第一行输入两个以空格隔开的整数 $n$ 和 $m$,分别表示对撞机的数量和询问数。 接下来 $m$ 行,表示询问,每行仅可能是 `+ i` 或 `- i`,表示开启或关闭第 $i$ 台对撞机。 ## 输出格式 输出 $m$ 行,输出结果按照上面题目给定格式输出。 ## 样例 #1 ### 样例输入 #1 ```cpp 10 10 + 6 + 10 + 5 - 10 - 5 - 6 + 10 + 3 + 6 + 3 ``` ### 样例输出 #1 ```cpp Success Conflict with 6 Success Already off Success Success Success Success Conflict with 3 Already on ``` ## 提示 **数据范围** $1 \le n,m \le 10^5$,$1 \le i \le n$。

题目描述

By 2312 there were $ n $ Large Hadron Colliders in the inhabited part of the universe. Each of them corresponded to a single natural number from $ 1 $ to $ n $ . However, scientists did not know what activating several colliders simultaneously could cause, so the colliders were deactivated. In 2312 there was a startling discovery: a collider's activity is safe if and only if all numbers of activated colliders are pairwise relatively prime to each other (two numbers are relatively prime if their greatest common divisor equals $ 1 $ )! If two colliders with relatively nonprime numbers are activated, it will cause a global collapse. Upon learning this, physicists rushed to turn the colliders on and off and carry out all sorts of experiments. To make sure than the scientists' quickness doesn't end with big trouble, the Large Hadron Colliders' Large Remote Control was created. You are commissioned to write the software for the remote (well, you do not expect anybody to operate it manually, do you?). Initially, all colliders are deactivated. Your program receives multiple requests of the form "activate/deactivate the $ i $ -th collider". The program should handle requests in the order of receiving them. The program should print the processed results in the format described below. To the request of "+ i" (that is, to activate the $ i $ -th collider), the program should print exactly one of the following responses: - "Success" if the activation was successful. - "Already on", if the $ i $ -th collider was already activated before the request. - "Conflict with j", if there is a conflict with the $ j $ -th collider (that is, the $ j $ -th collider is on, and numbers $ i $ and $ j $ are not relatively prime). In this case, the $ i $ -th collider shouldn't be activated. If a conflict occurs with several colliders simultaneously, you should print the number of any of them. The request of "- i" (that is, to deactivate the $ i $ -th collider), should receive one of the following responses from the program: - "Success", if the deactivation was successful. - "Already off", if the $ i $ -th collider was already deactivated before the request. You don't need to print quotes in the output of the responses to the requests.

输入输出格式

输入格式


The first line contains two space-separated integers $ n $ and $ m $ ( $ 1<=n,m<=10^{5} $ ) — the number of colliders and the number of requests, correspondingly. Next $ m $ lines contain numbers of requests, one per line, in the form of either "+ i" (without the quotes) — activate the $ i $ -th collider, or "- i" (without the quotes) — deactivate the $ i $ -th collider ( $ 1<=i<=n $ ).

输出格式


Print $ m $ lines — the results of executing requests in the above given format. The requests should be processed in the order, in which they are given in the input. Don't forget that the responses to the requests should be printed without quotes.

输入输出样例

输入样例 #1

10 10
+ 6
+ 10
+ 5
- 10
- 5
- 6
+ 10
+ 3
+ 6
+ 3

输出样例 #1

Success
Conflict with 6
Success
Already off
Success
Success
Success
Success
Conflict with 10
Already on

说明

Note that in the sample the colliders don't turn on after the second and ninth requests. The ninth request could also receive response "Conflict with 3".

Input

题意翻译

## 题目描述 在2312年,宇宙中发现了 $n$ 台巨型对撞机,这些对撞机分别用 $1 \sim n$ 的自然数标识。科学家们不知道启动这些对撞机会发生什么危险事故,所以这些机器,刚开始都是出于关闭的状态。 随着科学家们的研究发现,第 $i$ 台对撞机启动是安全的,当且仅当其他已经启动的对撞机的标识数都跟这台对撞机标识数互质。(例如假设前面启动的对撞机标识数是 $j$,如果 $i$ 能启动,那么 $i,j$ 互质,即 $\gcd(i,j) = 1$)。如果两台对撞机的标识数不为互质数就启动,那么就会发生爆炸事故。 基于前面的研究,科学家们准备做各种启动和关闭对撞机的实验。为了确保科学家们的生命安全,你要设计一个远程遥控的软件。 刚开始,所有的对撞机都是关闭状态。你的程序将会收到许多询问,格式为“启动、关闭第 $i$ 台对撞机”。这个程序应该能处理这些询问(根据收到询问的先后顺序处理)。程序按照如下的格式输出处理结果。 如果询问为 `+ i`(表示启动第 $i$ 台对撞机),程序应该按照下面三种情况之一输出结果。 - `Success`,表示启动第 $i$ 台是安全的。 - `Already on`,表示第 $i$ 台在询问之前就已经启动了。 - `Conflict with j`,表示第 $i$ 台与前面已经启动的第 $j$ 台冲突。如果前面有多台对撞机跟 $i$ 冲突,那么只输出其中任何一台即可。 如果询问为 `- i`(表示关闭第 $i$ 台对撞机),程序应该按照下面两种情况之一输出结果。 - `Success`,表示关闭第 $i$ 台对撞机。 - `Already off`,表示第 $i$ 台对撞机在询问之前就已经关闭了。 ## 输入格式 第一行输入两个以空格隔开的整数 $n$ 和 $m$,分别表示对撞机的数量和询问数。 接下来 $m$ 行,表示询问,每行仅可能是 `+ i` 或 `- i`,表示开启或关闭第 $i$ 台对撞机。 ## 输出格式 输出 $m$ 行,输出结果按照上面题目给定格式输出。 ## 样例 #1 ### 样例输入 #1 ```cpp 10 10 + 6 + 10 + 5 - 10 - 5 - 6 + 10 + 3 + 6 + 3 ``` ### 样例输出 #1 ```cpp Success Conflict with 6 Success Already off Success Success Success Success Conflict with 3 Already on ``` ## 提示 **数据范围** $1 \le n,m \le 10^5$,$1 \le i \le n$。

加入题单

上一题 下一题 算法标签: