#include<bits/stdc++.h>
using namespace std;
const int mxN = 1e6 + 1;
int cnt[mxN];
bool is[mxN];
int gcd(int a, int b){
if(b == 0)return a;
return gcd(b, a % b);
}
struct SegmentTree{
vector<int>sTree;
SegmentTree(int n){
sTree.resize(4 * n);
}
void Update(int node, int l, int r, int pos, int val){
if(l == r){
sTree[node] += val;
}
else{
int mid = (l + r) >> 1;
if(pos <= mid)Update(node * 2, l, mid, pos, val);
else Update(node * 2 + 1, mid + 1, r, pos, val);
sTree[node] = max(sTree[node * 2], sTree[node * 2 + 1]);
}
}
int Query(int node, int l, int r, int ql, int qr){
if(ql <= l && r <= qr)return sTree[node];
if(ql > r || l > qr)return -1e9;
int mid = (l + r) >> 1;
int lc = Query(node * 2, l, mid, ql, qr);
int rc = Query(node * 2 + 1, mid + 1, r, ql, qr);
return max(lc, rc);
}
int Get(int node, int l, int r, int pos){
if(l == r)return sTree[node];
int mid = (l + r) >> 1;
if(pos <= mid)return Get(node * 2, l, mid, pos);
return Get(node * 2 + 1, mid + 1, r, pos);
}
};
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, q;
cin >> n >> q;
vector<int>sieve(1e6 + 6, 1e9);
sieve[1] = 1;
for(int i = 2;i <= 1e6;++i){
if(sieve[i] == 1e9){
for(int j = i;j <= 1e6;j += i){
sieve[j] = min(sieve[j], i);
}
}
}
SegmentTree tree(n);
if(n <= 100 && q <= 200){
while(q--){
char type;
cin >> type;
if(type == 'C'){
int l, r;
cin >> l >> r;
vector<int>v;
for(int i = l;i <= r;++i){
if(is[i])v.push_back(i);
}
bool found = 0;
for(int i = 0;i < v.size();++i){
for(int j = i + 1;j < v.size();++j){
if(gcd(v[i], v[j]) > 1){
found = 1;
break;
}
}
if(found)break;
}
if(found){
cout << "DA\n";
}
else{
cout << "NE\n";
}
}
else{
int pos;
cin >> pos;
is[pos] ^= 1;
}
}
}
else{
while(q--){
char type;
cin >> type;
if(type == 'S'){
int pos;
cin >> pos;
vector<int>primes;
while(pos != 1){
int p = sieve[pos];
primes.push_back(p);
while(pos % p == 0){
pos /= p;
}
}
if(is[pos]){
for(int &i : primes){
tree.Update(1, 1, n, i, -1);
}
}
else{
for(int &i : primes){
tree.Update(1, 1, n, i, 1);
}
}
}
else{
int l, r;
cin >> l >> r;
int Q = tree.Query(1, 1, n, l, r);
if(Q > 1)cout << "DA\n";
else cout << "NE\n";
}
}
}
}
Compilation message
Main.cpp: In function 'int main()':
Main.cpp:69:33: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
69 | for(int i = 0;i < v.size();++i){
| ~~^~~~~~~~~~
Main.cpp:70:41: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
70 | for(int j = i + 1;j < v.size();++j){
| ~~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
4184 KB |
Output is correct |
2 |
Correct |
5 ms |
4188 KB |
Output is correct |
3 |
Correct |
5 ms |
4392 KB |
Output is correct |
4 |
Correct |
5 ms |
4184 KB |
Output is correct |
5 |
Correct |
5 ms |
4188 KB |
Output is correct |
6 |
Correct |
5 ms |
4188 KB |
Output is correct |
7 |
Correct |
5 ms |
4188 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
49 ms |
6988 KB |
Output is correct |
2 |
Correct |
72 ms |
13492 KB |
Output is correct |
3 |
Correct |
81 ms |
21336 KB |
Output is correct |
4 |
Incorrect |
10 ms |
5980 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
4184 KB |
Output is correct |
2 |
Correct |
5 ms |
4188 KB |
Output is correct |
3 |
Correct |
5 ms |
4392 KB |
Output is correct |
4 |
Correct |
5 ms |
4184 KB |
Output is correct |
5 |
Correct |
5 ms |
4188 KB |
Output is correct |
6 |
Correct |
5 ms |
4188 KB |
Output is correct |
7 |
Correct |
5 ms |
4188 KB |
Output is correct |
8 |
Correct |
49 ms |
6988 KB |
Output is correct |
9 |
Correct |
72 ms |
13492 KB |
Output is correct |
10 |
Correct |
81 ms |
21336 KB |
Output is correct |
11 |
Incorrect |
10 ms |
5980 KB |
Output isn't correct |
12 |
Halted |
0 ms |
0 KB |
- |