Submission #117993

# Submission time Handle Problem Language Result Execution time Memory
117993 2019-06-17T15:52:46 Z keko37 Tenis (COI19_tenis) C++14
51 / 100
500 ms 9576 KB
#include<bits/stdc++.h>

using namespace std;

const int MAXN = 100005;

int n, q, ofs = 1;
int p[4][MAXN], pos[4][MAXN], mx[MAXN], val[MAXN];

struct node {
    int val, pos, prop;
    node () {}
    node (int _val, int _pos, int _prop) {
        val = _val; pos = _pos; prop = _prop;
    }
} t[MAXN*3];

void ispis () {
    for (int i=0; i<2*ofs; i++) {
        cout << "bla " << i << "  " << t[i].val << " " << t[i].pos <<  " " << t[i].prop << endl;
    }
}

void propagate (int x) {
    if (t[x].prop == 0) return;
    t[x].val += t[x].prop;
    if (x < ofs) {
        t[2*x].prop += t[x].prop;
        t[2*x+1].prop += t[x].prop;
    }
    t[x].prop = 0;
}

node spoji (node a, node b) {
    if (a.val <= b.val) return a; else return b;
}

void update (int x, int from, int to, int low, int high, int br) {
    //cout << "update " << from << " " << to << "  " << br << endl;
    propagate(x);
    if (from <= low && high <= to) {
        t[x].prop += br;
        propagate(x);
        return;
    }
    if (to < low || high < from) return;
    update(2*x, from, to, low, (low + high)/2, br);
    update(2*x+1, from, to, (low + high)/2+1, high, br);
    t[x] = spoji(t[2*x], t[2*x+1]);
}

node upit (int x, int from, int to, int low, int high) {
    propagate(x);
    if (from <= low && high <= to) return t[x];
    if (to < low || high < from) return node(MAXN, n, 0);
    return spoji(upit(2*x, from, to, low, (low + high)/2), upit(2*x+1, from, to, (low + high)/2+1, high));
}

void ubaci (int v, int x, int sign) {
    if (x >= v) return;
    update(1, x-1, v-2, 0, ofs-1, sign);
}


void build () {
    while (ofs < n) ofs *= 2;
    for (int i=0; i<ofs; i++) {
        if (i < n) t[i + ofs] = node(0, i, 0); else t[i + ofs] = node(MAXN, n, 0);
    }
    for (int i=ofs-1; i>0; i--) {
        t[i] = spoji(t[2*i], t[2*i+1]);
    }
    //ispis();
    for (int i=1; i<=n; i++){
        ubaci(val[i], i, 1);
    }
}

void novi (int r, int s) {
    int v = 0;
    for (int i=1; i<=3; i++) {
        v = max(v, mx[p[i][s]]);
    }
    if (v != val[s]) {
        ubaci(val[s], s, -1);
        val[s] = v;
        ubaci(val[s], s, 1);
    }
}

void promjeni (int r, int a, int b) {
    //cout << "mijenjam " << r << " " << a << " " << b << endl;
    int x = pos[r][a], y = pos[r][b];
    p[r][x] = b; p[r][y] = a;
    pos[r][a] = y; pos[r][b] = x;
    mx[a] = mx[b] = 0;
    for (int i=1; i<=3; i++) {
        mx[a] = max(mx[a], pos[i][a]);
        mx[b] = max(mx[b], pos[i][b]);
    }
    for (int i=1; i<=3; i++) {
        novi(i, pos[i][a]);
        novi(i, pos[i][b]);
    }
}

int main () {
    //ios_base::sync_with_stdio(false);
    //cin.tie(0);
    cin >> n >> q;
    for (int i=1; i<=3; i++) {
        for (int j=1; j<=n; j++) {
            cin >> p[i][j];
            pos[i][p[i][j]] = j;
        }
    }
    for (int i=1; i<=n; i++) {
        for (int j=1; j<=3; j++) {
            mx[i] = max(mx[i], pos[j][i]);
        }
    }
    for (int i=1; i<=n; i++) {
        for (int j=1; j<=3; j++) {
            val[i] = max(val[i], mx[p[j][i]]);
        }
    }
    build();
    //ispis();
    for (int i=0; i<q; i++) {
        int tip;
        cin >> tip;
        if (tip == 1) {
            int a;
            cin >> a;
            int lim = upit(1, 0, n-1, 0, ofs-1).pos + 1;
            if (mx[a] <= lim) cout << "DA\n"; else cout << "NE\n";
        } else {
            int r, a, b;
            cin >> r >> a >> b;
            promjeni(r, a, b);
        }
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 3 ms 384 KB Output is correct
9 Correct 3 ms 384 KB Output is correct
10 Correct 3 ms 384 KB Output is correct
11 Correct 3 ms 384 KB Output is correct
12 Correct 3 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 3 ms 384 KB Output is correct
9 Correct 3 ms 384 KB Output is correct
10 Correct 3 ms 384 KB Output is correct
11 Correct 3 ms 384 KB Output is correct
12 Correct 3 ms 384 KB Output is correct
13 Correct 125 ms 8312 KB Output is correct
14 Correct 141 ms 8328 KB Output is correct
15 Correct 138 ms 8184 KB Output is correct
16 Correct 125 ms 8184 KB Output is correct
17 Correct 118 ms 8184 KB Output is correct
18 Correct 120 ms 8188 KB Output is correct
19 Correct 118 ms 8312 KB Output is correct
20 Correct 133 ms 8312 KB Output is correct
21 Correct 116 ms 8340 KB Output is correct
22 Correct 126 ms 8312 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 339 ms 8644 KB Output is correct
2 Correct 333 ms 8952 KB Output is correct
3 Correct 379 ms 9080 KB Output is correct
4 Correct 332 ms 8952 KB Output is correct
5 Correct 353 ms 8920 KB Output is correct
6 Correct 333 ms 8952 KB Output is correct
7 Correct 466 ms 9072 KB Output is correct
8 Correct 338 ms 9080 KB Output is correct
9 Correct 342 ms 8996 KB Output is correct
10 Correct 353 ms 8968 KB Output is correct
11 Correct 342 ms 9088 KB Output is correct
12 Correct 326 ms 8952 KB Output is correct
13 Correct 333 ms 9024 KB Output is correct
14 Correct 333 ms 8952 KB Output is correct
15 Correct 333 ms 9052 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 3 ms 384 KB Output is correct
9 Correct 3 ms 384 KB Output is correct
10 Correct 3 ms 384 KB Output is correct
11 Correct 3 ms 384 KB Output is correct
12 Correct 3 ms 384 KB Output is correct
13 Correct 125 ms 8312 KB Output is correct
14 Correct 141 ms 8328 KB Output is correct
15 Correct 138 ms 8184 KB Output is correct
16 Correct 125 ms 8184 KB Output is correct
17 Correct 118 ms 8184 KB Output is correct
18 Correct 120 ms 8188 KB Output is correct
19 Correct 118 ms 8312 KB Output is correct
20 Correct 133 ms 8312 KB Output is correct
21 Correct 116 ms 8340 KB Output is correct
22 Correct 126 ms 8312 KB Output is correct
23 Correct 339 ms 8644 KB Output is correct
24 Correct 333 ms 8952 KB Output is correct
25 Correct 379 ms 9080 KB Output is correct
26 Correct 332 ms 8952 KB Output is correct
27 Correct 353 ms 8920 KB Output is correct
28 Correct 333 ms 8952 KB Output is correct
29 Correct 466 ms 9072 KB Output is correct
30 Correct 338 ms 9080 KB Output is correct
31 Correct 342 ms 8996 KB Output is correct
32 Correct 353 ms 8968 KB Output is correct
33 Correct 342 ms 9088 KB Output is correct
34 Correct 326 ms 8952 KB Output is correct
35 Correct 333 ms 9024 KB Output is correct
36 Correct 333 ms 8952 KB Output is correct
37 Correct 333 ms 9052 KB Output is correct
38 Execution timed out 505 ms 9576 KB Time limit exceeded
39 Halted 0 ms 0 KB -