Submission #233477

# Submission time Handle Problem Language Result Execution time Memory
233477 2020-05-20T16:51:41 Z VEGAnn Tenis (COI19_tenis) C++14
100 / 100
225 ms 9500 KB
#include <bits/stdc++.h>
using namespace std;
const int N = 100100;
int n, q, loc[3][N], a[3][N], psh[4 * N];
array<int, 2> st[4 * N];

void build(int v, int l, int r){
    psh[v] = 0;

    if (l == r) {
        st[v] = {-(l + 1), l};
        return;
    }

    int md = (l + r) >> 1;

    build(v + v, l, md);
    build(v + v + 1, md + 1, r);

    st[v] = min(st[v + v], st[v + v + 1]);
}

void push(int v){
    if (psh[v] != 0){
        st[v][0] += psh[v];

        if (v + v + 1 < 4 * N){
            psh[v + v] += psh[v];
            psh[v + v + 1] += psh[v];
        }

        psh[v] = 0;
    }
}

void upd(int v, int tl, int tr, int l, int r, int vl){
    push(v);
    if (l > r) return;

    if (tl == l && tr == r){
        psh[v] += vl;
        push(v);
        return;
    }

    int md = (tl + tr) >> 1;

    upd(v + v, tl, md, l, min(r, md), vl);
    upd(v + v + 1, md + 1, tr, max(md + 1, l), r, vl);

    st[v] = min(st[v + v], st[v + v + 1]);
}

void update(int vl, int ad){
    int pos = min(loc[0][vl], min(loc[1][vl], loc[2][vl]));

    upd(1, 0, n - 1, pos, n - 1, ad);
}

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);

#ifdef _LOCAL
    freopen("in.txt","r",stdin);
#endif // _LOCAL

    cin >> n >> q;

    for (int tp = 0; tp < 3; tp++)
    for (int i = 0; i < n; i++){
        cin >> a[tp][i];
        a[tp][i]--;
        loc[tp][a[tp][i]] = i;
    }

    build(1, 0, n - 1);

    for (int i = 0; i < n; i++)
        update(i, +1);

    for (; q; q--){
        int tp; cin >> tp;

        if (tp == 1){
            int x; cin >> x; x--;

            cout << (st[1][1] >= loc[0][x] ? "DA\n" : "NE\n");
        } else {
            int x, y; cin >> tp >> x >> y;
            tp--; x--; y--;

            update(x, -1);
            update(y, -1);

            swap(loc[tp][x], loc[tp][y]);
            swap(a[tp][loc[tp][x]], a[tp][loc[tp][y]]);

            update(x, 1);
            update(y, 1);
        }
    }

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 512 KB Output is correct
9 Correct 5 ms 256 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 6 ms 432 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 512 KB Output is correct
9 Correct 5 ms 256 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 6 ms 432 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 82 ms 8056 KB Output is correct
14 Correct 75 ms 8056 KB Output is correct
15 Correct 73 ms 8056 KB Output is correct
16 Correct 76 ms 8056 KB Output is correct
17 Correct 73 ms 8056 KB Output is correct
18 Correct 78 ms 8056 KB Output is correct
19 Correct 78 ms 8056 KB Output is correct
20 Correct 78 ms 8056 KB Output is correct
21 Correct 71 ms 8056 KB Output is correct
22 Correct 72 ms 8056 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 99 ms 9080 KB Output is correct
2 Correct 95 ms 9060 KB Output is correct
3 Correct 96 ms 9080 KB Output is correct
4 Correct 104 ms 9208 KB Output is correct
5 Correct 92 ms 9080 KB Output is correct
6 Correct 96 ms 9080 KB Output is correct
7 Correct 100 ms 9136 KB Output is correct
8 Correct 96 ms 9208 KB Output is correct
9 Correct 104 ms 9080 KB Output is correct
10 Correct 101 ms 9080 KB Output is correct
11 Correct 91 ms 9080 KB Output is correct
12 Correct 97 ms 9208 KB Output is correct
13 Correct 99 ms 9080 KB Output is correct
14 Correct 98 ms 9080 KB Output is correct
15 Correct 94 ms 9080 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 512 KB Output is correct
9 Correct 5 ms 256 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 6 ms 432 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 82 ms 8056 KB Output is correct
14 Correct 75 ms 8056 KB Output is correct
15 Correct 73 ms 8056 KB Output is correct
16 Correct 76 ms 8056 KB Output is correct
17 Correct 73 ms 8056 KB Output is correct
18 Correct 78 ms 8056 KB Output is correct
19 Correct 78 ms 8056 KB Output is correct
20 Correct 78 ms 8056 KB Output is correct
21 Correct 71 ms 8056 KB Output is correct
22 Correct 72 ms 8056 KB Output is correct
23 Correct 99 ms 9080 KB Output is correct
24 Correct 95 ms 9060 KB Output is correct
25 Correct 96 ms 9080 KB Output is correct
26 Correct 104 ms 9208 KB Output is correct
27 Correct 92 ms 9080 KB Output is correct
28 Correct 96 ms 9080 KB Output is correct
29 Correct 100 ms 9136 KB Output is correct
30 Correct 96 ms 9208 KB Output is correct
31 Correct 104 ms 9080 KB Output is correct
32 Correct 101 ms 9080 KB Output is correct
33 Correct 91 ms 9080 KB Output is correct
34 Correct 97 ms 9208 KB Output is correct
35 Correct 99 ms 9080 KB Output is correct
36 Correct 98 ms 9080 KB Output is correct
37 Correct 94 ms 9080 KB Output is correct
38 Correct 222 ms 9396 KB Output is correct
39 Correct 122 ms 9212 KB Output is correct
40 Correct 225 ms 9436 KB Output is correct
41 Correct 134 ms 9208 KB Output is correct
42 Correct 141 ms 9336 KB Output is correct
43 Correct 206 ms 9340 KB Output is correct
44 Correct 119 ms 9204 KB Output is correct
45 Correct 149 ms 9336 KB Output is correct
46 Correct 125 ms 9176 KB Output is correct
47 Correct 137 ms 9208 KB Output is correct
48 Correct 126 ms 9336 KB Output is correct
49 Correct 140 ms 9208 KB Output is correct
50 Correct 124 ms 9208 KB Output is correct
51 Correct 161 ms 9336 KB Output is correct
52 Correct 205 ms 9500 KB Output is correct
53 Correct 132 ms 9208 KB Output is correct
54 Correct 132 ms 9216 KB Output is correct
55 Correct 161 ms 9300 KB Output is correct
56 Correct 153 ms 9336 KB Output is correct
57 Correct 132 ms 9208 KB Output is correct
58 Correct 167 ms 9208 KB Output is correct