#P1871. 对撞机

对撞机

Description

In the year 2312, nn giant colliders were discovered in the universe, labeled by the natural numbers 1n1 \sim n. Scientists do not know what dangerous accidents might occur when these colliders are turned on, so at the beginning all the machines are in the off state.

Through research, scientists found that turning on collider ii is safe if and only if the labels of all colliders that are already on are coprime with the label of collider ii. (For example, suppose a previously turned on collider has label jj, then if ii can be turned on, ii and jj are coprime, that is, gcd(i,j)=1\gcd(i,j) = 1.) If two colliders with labels that are not coprime are turned on, an explosion will occur.

Based on the above, scientists plan to run various experiments of turning colliders on and off. To ensure their safety, you need to design remote-control software.

Initially, all colliders are off. Your program will receive many queries of the form “turn on or turn off collider ii.” The program should process these queries in the order they are received and output results in the following format.

If a query is + i (turn on collider ii), the program should output exactly one of the following:

  • Success, meaning that turning on collider ii is safe.
  • Already on, meaning collider ii was already on before this query.
  • Conflict with j, meaning collider ii conflicts with some collider jj that is already on. If multiple colliders conflict with ii, output any one of them.

If a query is - i (turn off collider ii), the program should output exactly one of the following:

  • Success, meaning collider ii has been turned off.
  • Already off, meaning collider ii was already off before this query.

Input Format

The first line contains two space-separated integers nn and mm, the number of colliders and the number of queries.

The next mm lines are the queries. Each line is either + i or - i, meaning to turn on or turn off collider ii.

Output Format

Output mm lines. For each query, output the result in the format specified above.

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

Success
Conflict with 6
Success
Already off
Success
Success
Success
Success
Conflict with 3
Already on

Hint

Constraints

1n,m1051 \le n,m \le 10^5, 1in1 \le i \le n.


Thanks to @cn: 苏卿念 for providing the Special Judge.

Translated by ChatGPT 5