This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define int long long
#define see(x) cout<<#x<<"="<<x<<"\n";
#define endl "\n"
using namespace std;
const int N = 1e6+5;
const int INF = 1e18;
int n, q, p[N], a[N], cnt[N], used;
vector <int> prime;
void primes() {
for (int i = 2; i <= n; i ++) p[i] = 1;
for (int i = 2; i <= n; i ++) {
if (p[i]) {
for (int j = 2 * i; j <= n; j += i) {
p[j] = 0;
}
}
}
}
int32_t main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
/*
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
*/
cin >> n >> q;
primes();
while (q --) {
char c;
cin >> c;
if (c == 'S') {
int x;
cin >> x;
a[x] = 1 - a[x];
for (int i = 2; i * i <= x; i ++) {
if (x % i == 0) {
if (p[i]) {
if (a[x]) {
cnt[i] ++;
if (cnt[i] == 1) used ++;
}
else {
cnt[i] --;
if (!cnt[i]) used --;
}
}
if (p[x/i]) {
if (a[x]) {
cnt[x/i] ++;
if (cnt[x/i] == 1) used ++;
}
else {
cnt[x/i] --;
if (!cnt[x/i]) used --;
}
}
}
}
}
else {
int l, r;
cin >> l >> r;
if (used) cout << "DA\n";
else cout << "NE\n";
}
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |