#SP0000237. Bật và tắt máy va chạm (Colliders)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Bật và tắt máy va chạm (Colliders)
Colliders
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
There are colliders numbered through . Initially, all of them are switched off. The currently active colliders are safe exactly when the numbers assigned to every two distinct active colliders are coprime (their greatest common divisor is ).
Process requests in order:
+ i: try to activate collider . If it is already on, leave it unchanged. If a different active collider has a non-coprime number, reject the activation without changing the state. Otherwise activate it.- i: try to deactivate collider . If already off, nothing changes; otherwise switch it off.
Report the result of every request. If several active colliders conflict with an activation, reporting any one of their indices is accepted.
Input
- The first line contains integers , the number of colliders and requests.
- Each of the following lines contains
+or-, a space, and integer ().
Output
Print exactly lines, one per request:
Success: the requested state change succeeded.Already on: the collider was already active.Already off: the collider was already inactive.Conflict with j: the activation failed because active collider has ; any valid conflicting index is accepted.
Subtasks
-
Subtask 1 (20 points): ; ; every request is
+ ior- i, . -
Subtask 2 (30 points): ; ; every request is
+ ior- i, . -
Subtask 3 (50 points): ; ; every request is
+ ior- i, .
Examples
Input
10 10
+ 6
+ 10
+ 5
- 10
- 5
- 6
+ 10
+ 3
+ 6
+ 3
Output
Success
Conflict with 6
Success
Already off
Success
Success
Success
Success
Conflict with 10
Already on
Explanation
All colliders start off. Request 1 activates . Request 2 cannot activate because . Request 3 activates as . Request 4 attempts to deactivate the still-inactive , so it reports Already off. Requests 5 and 6 switch and off. Requests 7 and 8 successfully activate and , which are coprime. Request 9 tries to activate , but it conflicts with both (gcd ) and (gcd ); the sample chooses Conflict with 10, while Conflict with 3 is also valid. Request 10 reports Already on because remains active.