Submission #824962

# Submission time Handle Problem Language Result Execution time Memory
824962 2023-08-14T12:37:53 Z vjudge1 Werewolf (IOI18_werewolf) C++17
100 / 100
511 ms 99112 KB
#include<bits/stdc++.h>
#include "werewolf.h"

using namespace std;

struct SegTree {
    const static int N = (1 << 18);
    vector<int> t;
    SegTree() {
        t.assign(2 * N, -1);
    }
    void update(int pos, int val) {
        for(t[pos += N] = val; pos > 1; pos >>= 1) {
            t[pos >> 1] = max(t[pos], t[(pos ^ 1)]);
        }
    }
    int get(int ql, int qr) {
        int res = -1;
        for(ql += N, qr += N + 1; ql < qr; ql >>= 1, qr >>= 1) {
            if(ql & 1) res = max(t[ql++], res);
            if(qr & 1) res = max(t[--qr], res);
        }
        return res;
    }
};

struct DSU {
    vector<int> p, r;
    DSU(int n) {
        p.assign(n, 0);
        r.assign(n, 1);
        iota(p.begin(), p.end(), 0);
    }
    int find(int x) {
        return p[x] = (p[x] == x ? x : find(p[x]));
    }
    void merge(int u, int v) {
        u = find(u);
        v = find(v);
        if(u == v) return;
        p[v] = u;
    }
};
const int N = 200010;

struct Tree {
    vector<int> g[N];
    vector<int> order;
    int tin[N], tout[N], anc[N][18];

    void dfs(int s, int p) {
        tin[s] = (int)order.size();
        order.push_back(s);
        anc[s][0] = p;
        for(int i = 1; i < 18; i++) 
            anc[s][i] = anc[anc[s][i - 1]][i - 1];
            
        for(int to : g[s]) {
            if(to == p) continue;
            dfs(to, s);
        }
        tout[s] = (int)order.size() - 1;
    }
};

Tree LL, RR;
vector<int> g[N];
SegTree st;

vector<int> check_validity(int N, vector<int> X, vector<int> Y,
                                  vector<int> S, vector<int> T,
                                  vector<int> L, vector<int> R) {
    int m = (int)X.size(), q = (int)S.size();
    for(int i = 0; i < m; i++) {
        g[X[i]].push_back(Y[i]);
        g[Y[i]].push_back(X[i]);
    }
    DSU ds(N);
    for(int i = 0; i < N; i++) {
        for(int to : g[i]) {
            to = ds.find(to);
            if(to >= i) continue;
            ds.merge(i, to);
            RR.g[i].push_back(to);
        }
    }
    ds = DSU(N);
    for(int i = N - 1; i >= 0; i--) {
        for(int to : g[i]) {
            to = ds.find(to);
            if(to <= i) continue;
            ds.merge(i, to);
            LL.g[i].push_back(to);
        }
    }
    LL.dfs(0, 0);
    RR.dfs(N - 1, N - 1);
    vector<int> qr[N];
    vector<int> res(q);

    for(int i = 0; i < q; i++) {
        for(int k = 17; k >= 0; k--) {
            if(LL.anc[S[i]][k] >= L[i]) 
                S[i] = LL.anc[S[i]][k];
            if(RR.anc[T[i]][k] <= R[i])
                T[i] = RR.anc[T[i]][k];
        }
        qr[LL.tout[S[i]]].push_back(i);
    }
    for(int i = 0; i < N; i++) {
        int x = LL.order[i];
        st.update(RR.tin[x], i);
        for(int query : qr[i]) {
            int l = RR.tin[T[query]], r = RR.tout[T[query]];
            res[query] = (st.get(l, r) >= LL.tin[S[query]]); 
        }
    }   
    return res;
}

# Verdict Execution time Memory Grader output
1 Correct 8 ms 16468 KB Output is correct
2 Correct 11 ms 16476 KB Output is correct
3 Correct 8 ms 16476 KB Output is correct
4 Correct 8 ms 16472 KB Output is correct
5 Correct 9 ms 16468 KB Output is correct
6 Correct 8 ms 16468 KB Output is correct
7 Correct 8 ms 16468 KB Output is correct
8 Correct 8 ms 16528 KB Output is correct
9 Correct 8 ms 16472 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 16468 KB Output is correct
2 Correct 11 ms 16476 KB Output is correct
3 Correct 8 ms 16476 KB Output is correct
4 Correct 8 ms 16472 KB Output is correct
5 Correct 9 ms 16468 KB Output is correct
6 Correct 8 ms 16468 KB Output is correct
7 Correct 8 ms 16468 KB Output is correct
8 Correct 8 ms 16528 KB Output is correct
9 Correct 8 ms 16472 KB Output is correct
10 Correct 12 ms 17516 KB Output is correct
11 Correct 12 ms 17492 KB Output is correct
12 Correct 12 ms 17508 KB Output is correct
13 Correct 12 ms 17548 KB Output is correct
14 Correct 12 ms 17644 KB Output is correct
15 Correct 13 ms 17620 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 394 ms 90896 KB Output is correct
2 Correct 417 ms 90120 KB Output is correct
3 Correct 360 ms 89984 KB Output is correct
4 Correct 345 ms 90108 KB Output is correct
5 Correct 337 ms 90188 KB Output is correct
6 Correct 409 ms 90572 KB Output is correct
7 Correct 389 ms 90408 KB Output is correct
8 Correct 365 ms 90184 KB Output is correct
9 Correct 304 ms 89900 KB Output is correct
10 Correct 289 ms 89876 KB Output is correct
11 Correct 283 ms 89868 KB Output is correct
12 Correct 333 ms 90120 KB Output is correct
13 Correct 423 ms 94244 KB Output is correct
14 Correct 422 ms 94492 KB Output is correct
15 Correct 415 ms 94164 KB Output is correct
16 Correct 402 ms 94252 KB Output is correct
17 Correct 393 ms 90284 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 16468 KB Output is correct
2 Correct 11 ms 16476 KB Output is correct
3 Correct 8 ms 16476 KB Output is correct
4 Correct 8 ms 16472 KB Output is correct
5 Correct 9 ms 16468 KB Output is correct
6 Correct 8 ms 16468 KB Output is correct
7 Correct 8 ms 16468 KB Output is correct
8 Correct 8 ms 16528 KB Output is correct
9 Correct 8 ms 16472 KB Output is correct
10 Correct 12 ms 17516 KB Output is correct
11 Correct 12 ms 17492 KB Output is correct
12 Correct 12 ms 17508 KB Output is correct
13 Correct 12 ms 17548 KB Output is correct
14 Correct 12 ms 17644 KB Output is correct
15 Correct 13 ms 17620 KB Output is correct
16 Correct 394 ms 90896 KB Output is correct
17 Correct 417 ms 90120 KB Output is correct
18 Correct 360 ms 89984 KB Output is correct
19 Correct 345 ms 90108 KB Output is correct
20 Correct 337 ms 90188 KB Output is correct
21 Correct 409 ms 90572 KB Output is correct
22 Correct 389 ms 90408 KB Output is correct
23 Correct 365 ms 90184 KB Output is correct
24 Correct 304 ms 89900 KB Output is correct
25 Correct 289 ms 89876 KB Output is correct
26 Correct 283 ms 89868 KB Output is correct
27 Correct 333 ms 90120 KB Output is correct
28 Correct 423 ms 94244 KB Output is correct
29 Correct 422 ms 94492 KB Output is correct
30 Correct 415 ms 94164 KB Output is correct
31 Correct 402 ms 94252 KB Output is correct
32 Correct 393 ms 90284 KB Output is correct
33 Correct 450 ms 90432 KB Output is correct
34 Correct 192 ms 49224 KB Output is correct
35 Correct 471 ms 91288 KB Output is correct
36 Correct 443 ms 91000 KB Output is correct
37 Correct 454 ms 90828 KB Output is correct
38 Correct 414 ms 91192 KB Output is correct
39 Correct 454 ms 94212 KB Output is correct
40 Correct 511 ms 99112 KB Output is correct
41 Correct 365 ms 89900 KB Output is correct
42 Correct 346 ms 90828 KB Output is correct
43 Correct 497 ms 94408 KB Output is correct
44 Correct 453 ms 90348 KB Output is correct
45 Correct 369 ms 93436 KB Output is correct
46 Correct 420 ms 92960 KB Output is correct
47 Correct 404 ms 94788 KB Output is correct
48 Correct 402 ms 94216 KB Output is correct
49 Correct 435 ms 94296 KB Output is correct
50 Correct 435 ms 94668 KB Output is correct
51 Correct 490 ms 98616 KB Output is correct
52 Correct 458 ms 98472 KB Output is correct