이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define oo 1e17
#define pii pair<int, int>
const int MAX = 1e6 + 6;
int n, q;
set<int> p[MAX];
bool isOn[MAX];
vector<int> factors[MAX];
bool isP[MAX];
void sieve(){
memset(isP, 1, sizeof(isP));
for(int i = 2; i < MAX; i++){
if(!isP[i]) continue;
factors[i].push_back(i);
for(int j = i + i; j < MAX; j += i){
factors[j].push_back(i);
isP[j] = 0;
}
}
}
int main(){
sieve();
cin >> n >> q;
int anscnt = 0;
while(q--){
string t; cin >> t;
if(t[0] == 'S'){
int x; cin >> x;
if(!isOn[x]){
for(int a : factors[x]){
p[a].insert(x);
if(p[a].size() == 2){
anscnt++;
}
}
isOn[x] = 1;
}
else{
for(int a : factors[x]){
p[a].erase(x);
if(p[a].size() == 1){
anscnt--;
}
}
isOn[x] = 0;
}
}
else{
int l, r; cin >> l >> r;
if(anscnt){
cout << "DA\n";
}
else{
cout << "NE\n";
}
}
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |