#include <bits/stdc++.h>
using namespace std;
void solve1(int n, int q){
bool a[n + 1]; memset(a, false, sizeof(a));
while(q--) {
char t; cin >> t;
if (t == 'S') {
int x; cin >> x;
a[x] = !a[x];
}else{
int x, y; cin >> x >> y;
bool ans = true;
for (int i = x; i <= y; i++){
if (!a[i]) continue;
for (int j = i + 1; j <= y; j++){
if (a[j] && __gcd(i, j) > 1) {
ans = false; break;
}
}
if(ans) break;
}
if (ans) cout << "NE\n"; else cout << "DA\n";
}
}
}
void solve2(int n, int q){
vector<vector<int>> prime(n + 1);
for (int i = 2; i <= n; ++i){
if (!prime[i].empty()) continue;
for (int j = i; j <= n; j += i){
prime[j].push_back(i);
}
}
vector<int> cnt(n+1);
vector<bool> active(n+1);
int k = 0;
for (int i = 0; i < q; ++i){
char t; cin >> t;
if (t == 'S') {
int x; cin >> x;
if (!active[x]) {
for (auto p : prime[x]) {
cnt[p]++;
if (cnt[p] == 2) k++;
}
} else{
for (auto p : prime[x]){
cnt[p]--;
if (cnt[p] == 1) k--;
}
}
active[x] = !active[x];
} else{
int l, r; cin >> l >> r;
if (k > 0) cout << "DA\n";
else cout << "NE\n";
}
}
}
int main() {
int n, q; cin >> n >> q;
if (n < 101) solve1(n, q);
else solve2(n, q);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
61 ms |
7356 KB |
Output is correct |
2 |
Correct |
188 ms |
31568 KB |
Output is correct |
3 |
Correct |
354 ms |
61264 KB |
Output is correct |
4 |
Correct |
16 ms |
6448 KB |
Output is correct |
5 |
Correct |
137 ms |
30772 KB |
Output is correct |
6 |
Correct |
327 ms |
61288 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |