样例能过,但是0分qwq
#include <iostream>
using namespace std;
int gcd(int i,int j) {
int r;
while (j > 0) {
r = i % j;
i = j;
j = r;
}
return i;
}
int main() {
int n, m, p[100000],r=0;
bool s[10000];
char jd;
cin >> n >> m;
for (int i = 1; i <= m; i++) {
cin >> jd >> p[i];
int q = p[i];
if (jd == '+' ) {
if (i == 1) {
s[q] = true;
cout << "Success" << endl;
}
else {
if (gcd(p[i], p[i-1]) == 1 || (s[p[i-1]] == false && gcd(p[i],p[i-2]) == 1 ) || p[r] == 1){
p[r] = 0;
s[q] = true;
cout << "Success" << endl;
}
else if (s[q] == true)
cout << "Already on" << endl;
else {
s[q] = false;
cout << "Conflict with " << p[i - 1] <<endl;
}
//else cout << "Unknown error" << p[i]<<" "<< gcd(p[i], p[i-1])<<" "<<p[i-1]<<endl;
}
}
else if (jd == '-') {
if (i == 1) {
s[q] = false;
cout << "Already off" << endl;
}
else {
int t = p[i];
for (int j = 1; j <= m; j++) {
p[j] = p[i];
if (t == p[j])
t = p[j];
else t = 0;
}
if (s[q] == true) {
s[q] = false;
p[r] = 1;
cout << "Success" << endl;
}
else if (s[q] == false) cout << "Already off" << endl;
else cout << "Unknown error" << endl;
}
}
}
return 0;
}