답안 #586906

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
586906 2022-07-01T01:56:13 Z eecs Tenis (COI19_tenis) C++17
100 / 100
155 ms 5048 KB
#include <bits/stdc++.h>
using namespace std;

const int maxn = 100010;
int n, m, p[3][maxn], q[3][maxn];

#define mid ((l + r) >> 1)
#define ls (k << 1)
#define rs (k << 1 | 1)
int mn[maxn << 2], tag[maxn << 2];

void apply(int k, int v) {
    mn[k] += v, tag[k] += v;
}

void pushdown(int k) {
    if (tag[k]) apply(ls, tag[k]), apply(rs, tag[k]), tag[k] = 0;
}

void add(int k, int l, int r, int ql, int qr, int v) {
    if (l >= ql && r <= qr) return apply(k, v);
    pushdown(k);
    if (mid >= ql) add(ls, l, mid, ql, qr, v);
    if (mid < qr) add(rs, mid + 1, r, ql, qr, v);
    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];
    pushdown(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 >> m;
    for (int i : {0, 1, 2}) {
        for (int j = 1; j <= n; j++) {
            cin >> p[i][j], q[i][p[i][j]] = j;
        }
    }
    auto upd = [&](int x, int coef) {
        for (int i : {1, 2}) if (q[i][x] < q[0][x]) {
            add(1, 1, n, q[i][x], q[0][x] - 1, coef);
        }
    };
    for (int i = 1; i <= n; i++) {
        upd(i, 1);
    }
    while (m--) {
        int op, x, y, z;
        cin >> op >> x;
        if (op == 1) {
            int i = q[0][x];
            cout << (i == 1 || query(1, 1, n, 1, i - 1) ? "DA\n" : "NE\n");
        } else {
            cin >> y >> z, x--;
            upd(y, -1), upd(z, -1);
            swap(p[x][q[x][y]], p[x][q[x][z]]), swap(q[x][y], q[x][z]);
            upd(y, 1), upd(z, 1);
        }
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 396 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 396 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 43 ms 4620 KB Output is correct
14 Correct 47 ms 4720 KB Output is correct
15 Correct 43 ms 4688 KB Output is correct
16 Correct 43 ms 4692 KB Output is correct
17 Correct 55 ms 4660 KB Output is correct
18 Correct 56 ms 4660 KB Output is correct
19 Correct 38 ms 4564 KB Output is correct
20 Correct 48 ms 4640 KB Output is correct
21 Correct 41 ms 4556 KB Output is correct
22 Correct 41 ms 4692 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 73 ms 4952 KB Output is correct
2 Correct 90 ms 4956 KB Output is correct
3 Correct 91 ms 4980 KB Output is correct
4 Correct 69 ms 4912 KB Output is correct
5 Correct 72 ms 4968 KB Output is correct
6 Correct 75 ms 4908 KB Output is correct
7 Correct 93 ms 5000 KB Output is correct
8 Correct 70 ms 4940 KB Output is correct
9 Correct 77 ms 4980 KB Output is correct
10 Correct 76 ms 4940 KB Output is correct
11 Correct 85 ms 4940 KB Output is correct
12 Correct 109 ms 4992 KB Output is correct
13 Correct 75 ms 4940 KB Output is correct
14 Correct 72 ms 4940 KB Output is correct
15 Correct 79 ms 5008 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 396 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 43 ms 4620 KB Output is correct
14 Correct 47 ms 4720 KB Output is correct
15 Correct 43 ms 4688 KB Output is correct
16 Correct 43 ms 4692 KB Output is correct
17 Correct 55 ms 4660 KB Output is correct
18 Correct 56 ms 4660 KB Output is correct
19 Correct 38 ms 4564 KB Output is correct
20 Correct 48 ms 4640 KB Output is correct
21 Correct 41 ms 4556 KB Output is correct
22 Correct 41 ms 4692 KB Output is correct
23 Correct 73 ms 4952 KB Output is correct
24 Correct 90 ms 4956 KB Output is correct
25 Correct 91 ms 4980 KB Output is correct
26 Correct 69 ms 4912 KB Output is correct
27 Correct 72 ms 4968 KB Output is correct
28 Correct 75 ms 4908 KB Output is correct
29 Correct 93 ms 5000 KB Output is correct
30 Correct 70 ms 4940 KB Output is correct
31 Correct 77 ms 4980 KB Output is correct
32 Correct 76 ms 4940 KB Output is correct
33 Correct 85 ms 4940 KB Output is correct
34 Correct 109 ms 4992 KB Output is correct
35 Correct 75 ms 4940 KB Output is correct
36 Correct 72 ms 4940 KB Output is correct
37 Correct 79 ms 5008 KB Output is correct
38 Correct 143 ms 4780 KB Output is correct
39 Correct 88 ms 5020 KB Output is correct
40 Correct 154 ms 4724 KB Output is correct
41 Correct 131 ms 4860 KB Output is correct
42 Correct 100 ms 4864 KB Output is correct
43 Correct 141 ms 4848 KB Output is correct
44 Correct 94 ms 4856 KB Output is correct
45 Correct 155 ms 5048 KB Output is correct
46 Correct 94 ms 4948 KB Output is correct
47 Correct 104 ms 4908 KB Output is correct
48 Correct 102 ms 4940 KB Output is correct
49 Correct 104 ms 4780 KB Output is correct
50 Correct 93 ms 4884 KB Output is correct
51 Correct 101 ms 4880 KB Output is correct
52 Correct 151 ms 4844 KB Output is correct
53 Correct 122 ms 4884 KB Output is correct
54 Correct 93 ms 4812 KB Output is correct
55 Correct 103 ms 4836 KB Output is correct
56 Correct 94 ms 4840 KB Output is correct
57 Correct 115 ms 4920 KB Output is correct
58 Correct 129 ms 4896 KB Output is correct