Submission #467799

# Submission time Handle Problem Language Result Execution time Memory
467799 2021-08-24T14:16:09 Z couplefire Tenis (COI19_tenis) C++17
100 / 100
154 ms 7732 KB
#include <bits/stdc++.h>
using namespace std;
#define ll long long

const int N = 1<<17;

struct node{ll sum = 0, psum = 0;} tree[N<<1];
int n, q, pos[3][N];

void upd(int pos, int val, int v = 1, int tl = 0, int tr = N-1){
    if(tl==tr){
        tree[v].sum = val;
        tree[v].psum = tree[v].sum;
        return;
    }
    int tm = (tl+tr)>>1;
    if(pos<=tm) upd(pos, val, v<<1, tl, tm);
    else upd(pos, val, v<<1|1, tm+1, tr);
    tree[v].sum = tree[v<<1].sum+tree[v<<1|1].sum;
    tree[v].psum = min(tree[v<<1].psum, tree[v<<1].sum+min(tree[v<<1|1].psum, 0ll));
}

node query(int l, int r, int v = 1, int tl = 0, int tr = N-1){
    if(l<=tl && tr<=r) return tree[v];
    int tm = (tl+tr)>>1;
    if(r<=tm) return query(l, r, v<<1, tl, tm);
    else if(l>tm) return query(l, r, v<<1|1, tm+1, tr);
    node a = query(l, r, v<<1, tl, tm), b = query(l, r, v<<1|1, tm+1, tr);
    return {a.sum+b.sum, min(a.psum, a.sum+min(0ll, b.psum))};
}

int main(){
    // freopen("a.in", "r", stdin);
    cin.tie(0)->sync_with_stdio(0);
    cin >> n >> q;
    for(int i = 0; i<3; ++i)
        for(int j = 0; j<n; ++j){
            int a; cin >> a; --a;
            pos[i][a] = j;
        }
    for(int i = 0; i<n; ++i)
        upd(pos[0][i], pos[1][i]+pos[2][i]-2*pos[0][i]);
    while(q--){
        int _; cin >> _;
        if(_==1){
            int x; cin >> x; --x;
            if(pos[0][x]==0) cout << "DA" << '\n';
            else cout << (query(0, pos[0][x]-1).psum==0?"NE":"DA") << '\n';
        } else{
            int p, a, b; cin >> p >> a >> b; --p; --a; --b;
            swap(pos[p][a], pos[p][b]);
            upd(pos[0][a], pos[1][a]+pos[2][a]-2*pos[0][a]); 
            upd(pos[0][b], pos[1][b]+pos[2][b]-2*pos[0][b]);
        }
    }
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 388 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 388 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 328 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 388 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 328 KB Output is correct
13 Correct 59 ms 6332 KB Output is correct
14 Correct 62 ms 6352 KB Output is correct
15 Correct 56 ms 6344 KB Output is correct
16 Correct 59 ms 6208 KB Output is correct
17 Correct 56 ms 6340 KB Output is correct
18 Correct 57 ms 6328 KB Output is correct
19 Correct 56 ms 6212 KB Output is correct
20 Correct 65 ms 6480 KB Output is correct
21 Correct 84 ms 6332 KB Output is correct
22 Correct 65 ms 6348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 100 ms 7384 KB Output is correct
2 Correct 101 ms 7368 KB Output is correct
3 Correct 110 ms 7548 KB Output is correct
4 Correct 107 ms 7360 KB Output is correct
5 Correct 101 ms 7332 KB Output is correct
6 Correct 100 ms 7368 KB Output is correct
7 Correct 98 ms 7328 KB Output is correct
8 Correct 110 ms 7396 KB Output is correct
9 Correct 102 ms 7464 KB Output is correct
10 Correct 106 ms 7356 KB Output is correct
11 Correct 106 ms 7308 KB Output is correct
12 Correct 102 ms 7364 KB Output is correct
13 Correct 107 ms 7488 KB Output is correct
14 Correct 130 ms 7352 KB Output is correct
15 Correct 129 ms 7364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 388 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 328 KB Output is correct
13 Correct 59 ms 6332 KB Output is correct
14 Correct 62 ms 6352 KB Output is correct
15 Correct 56 ms 6344 KB Output is correct
16 Correct 59 ms 6208 KB Output is correct
17 Correct 56 ms 6340 KB Output is correct
18 Correct 57 ms 6328 KB Output is correct
19 Correct 56 ms 6212 KB Output is correct
20 Correct 65 ms 6480 KB Output is correct
21 Correct 84 ms 6332 KB Output is correct
22 Correct 65 ms 6348 KB Output is correct
23 Correct 100 ms 7384 KB Output is correct
24 Correct 101 ms 7368 KB Output is correct
25 Correct 110 ms 7548 KB Output is correct
26 Correct 107 ms 7360 KB Output is correct
27 Correct 101 ms 7332 KB Output is correct
28 Correct 100 ms 7368 KB Output is correct
29 Correct 98 ms 7328 KB Output is correct
30 Correct 110 ms 7396 KB Output is correct
31 Correct 102 ms 7464 KB Output is correct
32 Correct 106 ms 7356 KB Output is correct
33 Correct 106 ms 7308 KB Output is correct
34 Correct 102 ms 7364 KB Output is correct
35 Correct 107 ms 7488 KB Output is correct
36 Correct 130 ms 7352 KB Output is correct
37 Correct 129 ms 7364 KB Output is correct
38 Correct 124 ms 7652 KB Output is correct
39 Correct 106 ms 7496 KB Output is correct
40 Correct 147 ms 7732 KB Output is correct
41 Correct 111 ms 7464 KB Output is correct
42 Correct 109 ms 7624 KB Output is correct
43 Correct 132 ms 7612 KB Output is correct
44 Correct 103 ms 7492 KB Output is correct
45 Correct 154 ms 7560 KB Output is correct
46 Correct 115 ms 7496 KB Output is correct
47 Correct 103 ms 7536 KB Output is correct
48 Correct 110 ms 7476 KB Output is correct
49 Correct 110 ms 7492 KB Output is correct
50 Correct 100 ms 7496 KB Output is correct
51 Correct 107 ms 7480 KB Output is correct
52 Correct 125 ms 7660 KB Output is correct
53 Correct 103 ms 7612 KB Output is correct
54 Correct 105 ms 7480 KB Output is correct
55 Correct 142 ms 7488 KB Output is correct
56 Correct 114 ms 7616 KB Output is correct
57 Correct 105 ms 7460 KB Output is correct
58 Correct 111 ms 7512 KB Output is correct