답안 #540214

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
540214 2022-03-19T16:40:05 Z eecs Radio (COCI22_radio) C++17
110 / 110
1433 ms 212444 KB
#include <bits/stdc++.h>
using namespace std;

const int maxn = 1000010;
int n, q, cur[maxn], val[maxn], mn[maxn << 2];
vector<int> d[maxn];
set<int> S[maxn];
multiset<int> E[maxn];

#define ls (k << 1)
#define rs (k << 1 | 1)
#define mid ((l + r) >> 1)
void upd(int k, int l, int r, int p) {
    if (l == r) { mn[k] = val[l]; return; }
    mid >= p ? upd(ls, l, mid, p) : upd(rs, mid + 1, r, p);
    mn[k] = min(mn[ls], mn[rs]);
}

int query(int k, int l, int r, int ql, int qr) {
    if (l >= ql && r <= qr) return mn[k];
    int s = INT_MAX;
    if (mid >= ql) s = query(ls, l, mid, ql, qr);
    if (mid < qr) s = min(s, query(rs, mid + 1, r, ql, qr));
    return s;
}

int main() {
    ios::sync_with_stdio(0), cin.tie(0);
    cin >> n >> q;
    for (int i = 2; i <= n; i++) if (d[i].empty()) {
        for (int j = i; j <= n; j += i) d[j].push_back(i);
    }
    memset(mn, 0x3f, sizeof(mn));
    auto upd = [&](int p) {
        if (!p) return;
        val[p] = E[p].empty() ? INT_MAX : *E[p].begin();
        ::upd(1, 1, n, p);
    };
    while (q--) {
        char op;
        int x, y;
        cin >> op >> x;
        if (op == 'S') {
            for (int p : d[x]) {
                if (!cur[x]) {
                    auto it = S[p].insert(x).first;
                    int l = it == S[p].begin() ? 0 : *prev(it);
                    int r = next(it) == S[p].end() ? 0 : *next(it);
                    if (l) E[l].insert(x);
                    if (r) E[x].insert(r);
                    if (l && r) E[l].erase(E[l].find(r));
                    upd(l), upd(x);
                } else {
                    auto it = S[p].lower_bound(x);
                    int l = it == S[p].begin() ? 0 : *prev(it);
                    int r = next(it) == S[p].end() ? 0 : *next(it);
                    if (l) E[l].erase(E[l].find(x));
                    if (r) E[x].erase(E[x].find(r));
                    if (l && r) E[l].insert(r);
                    upd(l), upd(x);
                    S[p].erase(x);
                }
            }
            cur[x] ^= 1;
        } else {
            cin >> y;
            cout << (query(1, 1, n, x, y) <= y ? "DA\n" : "NE\n");
        }
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 65 ms 133324 KB Output is correct
2 Correct 68 ms 133396 KB Output is correct
3 Correct 70 ms 133344 KB Output is correct
4 Correct 67 ms 133440 KB Output is correct
5 Correct 71 ms 133324 KB Output is correct
6 Correct 71 ms 133360 KB Output is correct
7 Correct 67 ms 133320 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 539 ms 148292 KB Output is correct
2 Correct 976 ms 181680 KB Output is correct
3 Correct 1243 ms 207676 KB Output is correct
4 Correct 103 ms 137300 KB Output is correct
5 Correct 270 ms 153264 KB Output is correct
6 Correct 524 ms 173368 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 65 ms 133324 KB Output is correct
2 Correct 68 ms 133396 KB Output is correct
3 Correct 70 ms 133344 KB Output is correct
4 Correct 67 ms 133440 KB Output is correct
5 Correct 71 ms 133324 KB Output is correct
6 Correct 71 ms 133360 KB Output is correct
7 Correct 67 ms 133320 KB Output is correct
8 Correct 539 ms 148292 KB Output is correct
9 Correct 976 ms 181680 KB Output is correct
10 Correct 1243 ms 207676 KB Output is correct
11 Correct 103 ms 137300 KB Output is correct
12 Correct 270 ms 153264 KB Output is correct
13 Correct 524 ms 173368 KB Output is correct
14 Correct 276 ms 133844 KB Output is correct
15 Correct 703 ms 141304 KB Output is correct
16 Correct 1433 ms 212444 KB Output is correct
17 Correct 1179 ms 204788 KB Output is correct
18 Correct 1294 ms 208840 KB Output is correct
19 Correct 1320 ms 208920 KB Output is correct
20 Correct 517 ms 173244 KB Output is correct
21 Correct 514 ms 173264 KB Output is correct
22 Correct 540 ms 173180 KB Output is correct
23 Correct 503 ms 173388 KB Output is correct