#include<bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5;
const int INF = 1e9;
int spf[N], is[N];
set < int > st, g[N];
void precompute(){
for(int i = 2; i < N; i++)
spf[i] = INF;
for(int i = 2; i < N; i++){
if(spf[i] != INF)continue;
for(int j = i; j < N; j += i){
spf[j] = min(spf[j], i);
}
}
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
precompute();
int n, q;
cin >> n >> q;
while(q--){
char type;
cin >> type;
if(type == 'S'){
int ps;
cin >> ps;
is[ps] ^= 1;
int x = ps;
while(x != 1){
int xx = spf[x];
if(is[ps] == 1){
g[xx].insert(ps);
if(g[xx].size() == 2){
st.insert(xx);
}
}
else {
g[xx].erase(ps);
if(g[xx].size() == 1){
st.erase(xx);
}
}
x /= xx;
}
}
else {
int l, r;
cin >> l >> r;
bool ok = false;
for(auto i : st){
auto it = g[i].lower_bound(l);
int ql = *(it);
int qr = *(++it);
if(l <= ql && qr <= r){
ok = true;
break;
}
}
cout << (ok ? "Yes" : "No") << endl;
}
}
}
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |