/**
* author: wxhtzdy
* created: 13.06.2022 22:14:19
**/
#include <bits/stdc++.h>
using namespace std;
const int MAX = 1000005;
const int inf = (int) 1e9;
int mn[4 * MAX];
void build(int node, int l, int r) {
mn[node] = inf;
if (l == r) {
return;
}
int mid = l + r >> 1;
build(node * 2, l, mid);
build(node * 2 + 1, mid + 1, r);
}
void modify(int node, int l, int r, int i, int v) {
if (l == r) {
mn[node] = v;
return;
}
int mid = l + r >> 1;
if (i <= mid) {
modify(node * 2, l, mid, i, v);
} else {
modify(node * 2 + 1, mid + 1, r, i, v);
}
mn[node] = min(mn[node * 2], mn[node * 2 + 1]);
}
int get(int node, int l, int r, int ll, int rr) {
if (l > r || l > rr || r < ll) {
return inf;
}
if (ll <= l && r <= rr) {
return mn[node];
}
int mid = l + r >> 1;
return min(get(node * 2, l, mid, ll, rr), get(node * 2 + 1, mid + 1, r, ll, rr));
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
vector<vector<int>> d(MAX);
for (int i = 2; i < MAX; i++) {
if (d[i].empty()) {
for (int j = i; j < MAX; j += i) {
d[j].push_back(i);
}
}
}
build(1, 1, MAX);
vector<multiset<int>> f(MAX);
for (int i = 0; i < MAX; i++) {
f[i].insert(inf);
}
function<void(int, int)> Add_seg = [&](int l, int r) {
f[l].insert(r);
modify(1, 1, MAX, l, *f[l].begin());
};
function<void(int, int)> Del_seg = [&](int l, int r) {
f[l].erase(f[l].find(r));
modify(1, 1, MAX, l, *f[l].begin());
};
vector<set<int>> at(MAX);
function<void(int)> Del = [&](int x) {
for (int i : d[x]) {
auto it = at[i].find(x);
if (it != at[i].begin()) {
Del_seg(x, *prev(it));
}
if (it != prev(at[i].end())) {
Del_seg(x, *next(it));
}
if (it != at[i].begin() && it != prev(at[i].end())) {
Add_seg(*prev(it), *next(it));
}
at[i].erase(it);
}
};
function<void(int)> Add = [&](int x) {
for (int i : d[x]) {
auto it = at[i].lower_bound(x);
if (it != at[i].begin() && it != at[i].end()) {
Del_seg(*prev(it), *it);
}
if (it != at[i].begin()) {
Add_seg(*prev(it), x);
}
if (it != at[i].end()) {
Add_seg(x, *it);
}
at[i].insert(x);
}
};
int n, q;
cin >> n >> q;
vector<bool> act(MAX);
while (q--) {
char foo;
cin >> foo;
if (foo == 'S') {
int x;
cin >> x;
if (act[x]) {
Del(x);
} else {
Add(x);
}
act[x] = !act[x];
} else {
int l, r;
cin >> l >> r;
cout << (get(1, 1, MAX, l, r) <= r ? "DA" : "NE") << '\n';
}
}
return 0;
}
Compilation message
Main.cpp: In function 'void build(int, int, int)':
Main.cpp:20:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
20 | int mid = l + r >> 1;
| ~~^~~
Main.cpp: In function 'void modify(int, int, int, int, int)':
Main.cpp:30:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
30 | int mid = l + r >> 1;
| ~~^~~
Main.cpp: In function 'int get(int, int, int, int, int)':
Main.cpp:46:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
46 | int mid = l + r >> 1;
| ~~^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
557 ms |
415464 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
556 ms |
415736 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
557 ms |
415464 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |