#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
const ll maxn = 1e6 + 5;
const ll mod = 1e9 + 7;
const ll inf = 2e18;
#define TextIO ifstream fileIn("input.txt"); cin.rdbuf(fileIn.rdbuf()); ofstream fileOut("output.txt"); cout.rdbuf(fileOut.rdbuf());
#define FastIO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define print(x) for (auto i : x) cout << i << ' '; cout << endl
#define out(x) {cout << x << endl; return;}
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define endl '\n'
ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b);}
ll lcm(ll a, ll b) { return (a * b) / gcd(a, b); }
ll pw(ll a, ll b, ll md = mod) {ll res = 1; b = max(b, 0ll); while(b) {if (b & 1){res = (a * res) % md;} a = (a * a) % md; b >>= 1;} return (res % md);}
ll n, q;
vll d[maxn];
ll vis[maxn];
ll ans[maxn];
ll c2 = 0;
void solve() {
cin >> n >> q;
ll ind = 0;;
for (ll i = 2; i <= n; i++) {
if (d[i].size() == 0) {
for (ll j = i; j <= n; j+=i)
d[j].pb(ind);
ind++;
}
}
while (q--) {
char t;
cin >> t;
if (t == 'S') {
ll x;
cin >> x;
if (vis[x]) {
for (auto &a : d[x]) {
ans[a]--;
if (ans[a] == 1) c2--;
}
vis[x] = 0;
}
else {
for (auto &a : d[x]) {
ans[a]++;
if (ans[a] == 2) c2++;
}
vis[x] = 1;
}
}
else {
ll l, r;
cin >> l >> r;
cout << (c2 ? "DA" : "NE") << endl;
}
}
}
int main() {
FastIO
ll t = 1;
// cin >> t;
while (t--)
solve();
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... |