Submission #166216

# Submission time Handle Problem Language Result Execution time Memory
166216 2019-12-01T09:15:44 Z farmerboy Tenis (COI19_tenis) C++14
100 / 100
288 ms 14420 KB
/*
    Author: Nguyen Tan Bao
    Status:
    Idea:
*/
 
#include <bits/stdc++.h>
#define FI first
#define SE second
#define EPS 1e-9
#define ALL(a) a.begin(),a.end()
#define SZ(a) int((a).size())
#define MS(s, n) memset(s, n, sizeof(s))
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
//__builtin_ffs(x) return 1 + index of least significant 1-bit of x
//__builtin_clz(x) return number of leading zeros of x
//__builtin_ctz(x) return number of trailing zeros of x
 
using namespace std;
using ll = long long;
using ld = double;
typedef pair<int, int> II;
typedef pair<int, II> III;
typedef complex<ld> cd;
typedef vector<cd> vcd;
 
const ll MODBASE = 1000000007LL;
const int MAXN = 100010;
const int MAXM = 1000;
const int MAXK = 16;
const int MAXQ = 200010;

int n, q, a[4][MAXN], Max[MAXN], D[MAXN], b[MAXN][4], laz[MAXN * 8];

struct Data {
    int Min, pos;
    Data(int Min = 1000000000, int pos = 1000000000) : Min(Min), pos(pos) {}
} t[MAXN*8];

bool operator< (Data a, Data b) {
    if (a.Min != b.Min) return a.Min < b.Min;
    return a.pos < b.pos;
}

void build(int k, int l, int r) {
    if (l > r) return;
    if (l == r) {
        t[k].Min = D[l];
        t[k].pos = l;
        return;
    }
    int m = (l + r) >> 1;
    build(k*2, l, m);
    build(k*2+1, m+1, r);
    t[k] = min(t[k*2], t[k*2+1]);
}

void lazyUpdate(int k, int l, int r) {
    if (l > r) return;
    if (laz[k] == 0) return;
    t[k].Min += laz[k];
    if (l < r) {
        laz[k*2] += laz[k];
        laz[k*2+1] += laz[k];
    }
    laz[k] = 0;
}

void update(int k, int l, int r, int u, int v, int gt) {
    // cout << k << ' ' << l << ' ' << r << ' ' << u << ' ' << v << ' ' << gt << endl;
    lazyUpdate(k,l,r);
    if (l > r || r < u || v < l) return;
    if (u <= l && r <= v) {
        laz[k] += gt;
        lazyUpdate(k,l,r);
        return;
    }
    int m = (l + r) >> 1;
    update(k*2, l, m, u, v, gt);
    update(k*2+1, m+1, r, u, v, gt);
    t[k] = min(t[k*2], t[k*2+1]);
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    cin >> n >> q;
    FOR(i,1,3)
        FOR(j,1,n) {
            cin >> a[i][j];
            b[a[i][j]][i] = j;
        }

    FOR(i,1,3)
        FOR(j,1,n) Max[a[i][j]] = max(Max[a[i][j]], j);
    
    FOR(i,1,n) D[Max[i]]--;
    FOR(i,1,n) D[i] += D[i-1];
    FOR(i,1,n) D[i] += i;
    // FOR(i,1,n) cout << D[i] << ' '; cout << endl;
    build(1,1,n);

    while (q--) {
        int ch, p, u, v;
        cin >> ch;
        if (ch == 1) {
            cin >> u;
            // cout << t[1].Min << ' ' << t[1].pos << endl;
            if (t[1].Min) cout << "NE\n";
            else if (Max[u] <= t[1].pos) cout << "DA\n";
            else cout << "NE\n";
        }
        else {
            cin >> p >> u >> v;
            int x1 = b[u][p], x2 = b[v][p];
            b[u][p] = x2;
            b[v][p] = x1;
            update(1,1,n,Max[u],n,1);
            update(1,1,n,Max[v],n,1);

            Max[u] = 0; Max[v] = 0;
            FOR(i,1,3) {
                Max[u] = max(Max[u], b[u][i]);
                Max[v] = max(Max[v], b[v][i]);
            }
            
            update(1,1,n,Max[u],n,-1);
            update(1,1,n,Max[v],n,-1);
        }
    }

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 7 ms 6648 KB Output is correct
2 Correct 8 ms 6648 KB Output is correct
3 Correct 8 ms 6648 KB Output is correct
4 Correct 8 ms 6648 KB Output is correct
5 Correct 8 ms 6648 KB Output is correct
6 Correct 8 ms 6648 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 6648 KB Output is correct
2 Correct 8 ms 6648 KB Output is correct
3 Correct 8 ms 6648 KB Output is correct
4 Correct 8 ms 6648 KB Output is correct
5 Correct 8 ms 6648 KB Output is correct
6 Correct 8 ms 6648 KB Output is correct
7 Correct 8 ms 6648 KB Output is correct
8 Correct 8 ms 6680 KB Output is correct
9 Correct 9 ms 6652 KB Output is correct
10 Correct 8 ms 6652 KB Output is correct
11 Correct 8 ms 6648 KB Output is correct
12 Correct 8 ms 6648 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 6648 KB Output is correct
2 Correct 8 ms 6648 KB Output is correct
3 Correct 8 ms 6648 KB Output is correct
4 Correct 8 ms 6648 KB Output is correct
5 Correct 8 ms 6648 KB Output is correct
6 Correct 8 ms 6648 KB Output is correct
7 Correct 8 ms 6648 KB Output is correct
8 Correct 8 ms 6680 KB Output is correct
9 Correct 9 ms 6652 KB Output is correct
10 Correct 8 ms 6652 KB Output is correct
11 Correct 8 ms 6648 KB Output is correct
12 Correct 8 ms 6648 KB Output is correct
13 Correct 53 ms 12008 KB Output is correct
14 Correct 65 ms 12124 KB Output is correct
15 Correct 53 ms 11896 KB Output is correct
16 Correct 55 ms 11952 KB Output is correct
17 Correct 53 ms 11900 KB Output is correct
18 Correct 52 ms 11896 KB Output is correct
19 Correct 55 ms 11904 KB Output is correct
20 Correct 56 ms 12024 KB Output is correct
21 Correct 53 ms 11896 KB Output is correct
22 Correct 53 ms 11896 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 77 ms 12972 KB Output is correct
2 Correct 73 ms 12880 KB Output is correct
3 Correct 75 ms 13048 KB Output is correct
4 Correct 75 ms 13048 KB Output is correct
5 Correct 79 ms 12992 KB Output is correct
6 Correct 76 ms 12900 KB Output is correct
7 Correct 74 ms 13020 KB Output is correct
8 Correct 77 ms 13056 KB Output is correct
9 Correct 83 ms 13048 KB Output is correct
10 Correct 79 ms 12848 KB Output is correct
11 Correct 73 ms 12920 KB Output is correct
12 Correct 75 ms 12948 KB Output is correct
13 Correct 73 ms 12920 KB Output is correct
14 Correct 72 ms 12920 KB Output is correct
15 Correct 73 ms 13048 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 6648 KB Output is correct
2 Correct 8 ms 6648 KB Output is correct
3 Correct 8 ms 6648 KB Output is correct
4 Correct 8 ms 6648 KB Output is correct
5 Correct 8 ms 6648 KB Output is correct
6 Correct 8 ms 6648 KB Output is correct
7 Correct 8 ms 6648 KB Output is correct
8 Correct 8 ms 6680 KB Output is correct
9 Correct 9 ms 6652 KB Output is correct
10 Correct 8 ms 6652 KB Output is correct
11 Correct 8 ms 6648 KB Output is correct
12 Correct 8 ms 6648 KB Output is correct
13 Correct 53 ms 12008 KB Output is correct
14 Correct 65 ms 12124 KB Output is correct
15 Correct 53 ms 11896 KB Output is correct
16 Correct 55 ms 11952 KB Output is correct
17 Correct 53 ms 11900 KB Output is correct
18 Correct 52 ms 11896 KB Output is correct
19 Correct 55 ms 11904 KB Output is correct
20 Correct 56 ms 12024 KB Output is correct
21 Correct 53 ms 11896 KB Output is correct
22 Correct 53 ms 11896 KB Output is correct
23 Correct 77 ms 12972 KB Output is correct
24 Correct 73 ms 12880 KB Output is correct
25 Correct 75 ms 13048 KB Output is correct
26 Correct 75 ms 13048 KB Output is correct
27 Correct 79 ms 12992 KB Output is correct
28 Correct 76 ms 12900 KB Output is correct
29 Correct 74 ms 13020 KB Output is correct
30 Correct 77 ms 13056 KB Output is correct
31 Correct 83 ms 13048 KB Output is correct
32 Correct 79 ms 12848 KB Output is correct
33 Correct 73 ms 12920 KB Output is correct
34 Correct 75 ms 12948 KB Output is correct
35 Correct 73 ms 12920 KB Output is correct
36 Correct 72 ms 12920 KB Output is correct
37 Correct 73 ms 13048 KB Output is correct
38 Correct 219 ms 14296 KB Output is correct
39 Correct 114 ms 13176 KB Output is correct
40 Correct 224 ms 14328 KB Output is correct
41 Correct 134 ms 13236 KB Output is correct
42 Correct 132 ms 13268 KB Output is correct
43 Correct 212 ms 14420 KB Output is correct
44 Correct 105 ms 13048 KB Output is correct
45 Correct 139 ms 13276 KB Output is correct
46 Correct 111 ms 13236 KB Output is correct
47 Correct 126 ms 13244 KB Output is correct
48 Correct 111 ms 13024 KB Output is correct
49 Correct 140 ms 13912 KB Output is correct
50 Correct 107 ms 13080 KB Output is correct
51 Correct 139 ms 13356 KB Output is correct
52 Correct 221 ms 13732 KB Output is correct
53 Correct 126 ms 13176 KB Output is correct
54 Correct 123 ms 13200 KB Output is correct
55 Correct 141 ms 13344 KB Output is correct
56 Correct 137 ms 13176 KB Output is correct
57 Correct 288 ms 13020 KB Output is correct
58 Correct 162 ms 14200 KB Output is correct