Submission #414103

# Submission time Handle Problem Language Result Execution time Memory
414103 2021-05-30T03:53:08 Z ja_kingy Werewolf (IOI18_werewolf) C++14
100 / 100
1488 ms 212424 KB
#include "werewolf.h"
#include <bits/stdc++.h>
using namespace std;

//10:20

const int mxN = 2e5;
template <class T>
struct KRT {
    int ncnt, dsu[2*mxN], val[2*mxN], anc[2*mxN][19];
    vector<int> g[2*mxN];
    T cmp;
    int f(int x) {return dsu[x] == x ? x : dsu[x] = f(dsu[x]);}
    KRT (int n, vector<int> &u, vector<int> &v) : ncnt(n) {
        iota(begin(dsu), end(dsu), 0);
        vector<int> order(u.size());
        iota(order.begin(), order.end(), 0);
        sort(order.begin(), order.end(), [&](int a, int b) {return cmp(max(u[a], v[a], cmp), max(u[b], v[b], cmp));});
        for (int e: order) {
            int a = f(u[e]), b = f(v[e]);
            if (a != b) {
                anc[a][0] = anc[b][0] = dsu[b] = dsu[a] = ncnt;
                val[ncnt] = max(u[e], v[e], cmp);
                g[ncnt].push_back(a);
                g[ncnt].push_back(b);
                ncnt++;
            }            
        }
        anc[ncnt-1][0] = ncnt-1;
        for (int i = 1; i < 19; ++i) for (int j = 0; j < ncnt; ++j) anc[j][i] = ncnt-1;
        for (int i = 1; i < 19; ++i) {
            for (int j = 0; j < ncnt; ++j) {
                anc[j][i] = anc[anc[j][i-1]][i-1];
            }
        }
    }
    int thresh(int x, int v) {
        for (int i = 19; i--;) {
            if (!cmp(v,val[anc[x][i]])) x = anc[x][i]; 
        }
        return x;
    }
};

int tcnt, st[2*mxN], en[2*mxN];
void dfs1(int u, KRT<less<int>> &k) {
    st[u] = tcnt++;
    for (int v: k.g[u]) dfs1(v, k);
    en[u] = tcnt;
}

struct qry {int l, r, id;};
vector<qry> qrys[2*mxN];
vector<int> ans;
set<int> sts[2*mxN];
void dfs2(int u, KRT<greater<int>> &k) {
    for (int v: k.g[u]) {
        dfs2(v, k);
        if (sts[u].size() < sts[v].size()) swap(sts[u], sts[v]);
        sts[u].insert(sts[v].begin(), sts[v].end());
    }
    for (qry q: qrys[u]) {
        auto it = sts[u].lower_bound(q.l);
        ans[q.id] = it != sts[u].end() && *it < q.r;
    }
}

vector<int> check_validity(int N, vector<int> X, vector<int> Y,
                                vector<int> S, vector<int> E,
                                vector<int> L, vector<int> R) {
    int Q = S.size();
    ans.resize(Q);
    KRT<less<int>> wolf(N,X,Y);
    KRT<greater<int>> human(N,X,Y);
    dfs1(wolf.ncnt-1, wolf);
    for (int i = 0; i < N; ++i) sts[i].insert(st[i]);
    for (int i = 0; i < Q; ++i) {
        int x = wolf.thresh(E[i], R[i]);
        qrys[human.thresh(S[i], L[i])].push_back({st[x], en[x], i});
    }
    dfs2(human.ncnt-1, human);
    return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 59 ms 112960 KB Output is correct
2 Correct 60 ms 112924 KB Output is correct
3 Correct 59 ms 112964 KB Output is correct
4 Correct 59 ms 112988 KB Output is correct
5 Correct 59 ms 112964 KB Output is correct
6 Correct 62 ms 112964 KB Output is correct
7 Correct 64 ms 113036 KB Output is correct
8 Correct 60 ms 112956 KB Output is correct
9 Correct 59 ms 112952 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 59 ms 112960 KB Output is correct
2 Correct 60 ms 112924 KB Output is correct
3 Correct 59 ms 112964 KB Output is correct
4 Correct 59 ms 112988 KB Output is correct
5 Correct 59 ms 112964 KB Output is correct
6 Correct 62 ms 112964 KB Output is correct
7 Correct 64 ms 113036 KB Output is correct
8 Correct 60 ms 112956 KB Output is correct
9 Correct 59 ms 112952 KB Output is correct
10 Correct 72 ms 114124 KB Output is correct
11 Correct 68 ms 114028 KB Output is correct
12 Correct 71 ms 114296 KB Output is correct
13 Correct 74 ms 114032 KB Output is correct
14 Correct 70 ms 114260 KB Output is correct
15 Correct 68 ms 114104 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1352 ms 210376 KB Output is correct
2 Correct 1264 ms 178548 KB Output is correct
3 Correct 1191 ms 186952 KB Output is correct
4 Correct 1207 ms 201392 KB Output is correct
5 Correct 1211 ms 204552 KB Output is correct
6 Correct 1297 ms 209616 KB Output is correct
7 Correct 1313 ms 212424 KB Output is correct
8 Correct 1188 ms 178292 KB Output is correct
9 Correct 1008 ms 186308 KB Output is correct
10 Correct 1071 ms 200908 KB Output is correct
11 Correct 1054 ms 202260 KB Output is correct
12 Correct 1160 ms 208072 KB Output is correct
13 Correct 1284 ms 179496 KB Output is correct
14 Correct 1284 ms 179204 KB Output is correct
15 Correct 1288 ms 179264 KB Output is correct
16 Correct 1305 ms 179112 KB Output is correct
17 Correct 1335 ms 210044 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 59 ms 112960 KB Output is correct
2 Correct 60 ms 112924 KB Output is correct
3 Correct 59 ms 112964 KB Output is correct
4 Correct 59 ms 112988 KB Output is correct
5 Correct 59 ms 112964 KB Output is correct
6 Correct 62 ms 112964 KB Output is correct
7 Correct 64 ms 113036 KB Output is correct
8 Correct 60 ms 112956 KB Output is correct
9 Correct 59 ms 112952 KB Output is correct
10 Correct 72 ms 114124 KB Output is correct
11 Correct 68 ms 114028 KB Output is correct
12 Correct 71 ms 114296 KB Output is correct
13 Correct 74 ms 114032 KB Output is correct
14 Correct 70 ms 114260 KB Output is correct
15 Correct 68 ms 114104 KB Output is correct
16 Correct 1352 ms 210376 KB Output is correct
17 Correct 1264 ms 178548 KB Output is correct
18 Correct 1191 ms 186952 KB Output is correct
19 Correct 1207 ms 201392 KB Output is correct
20 Correct 1211 ms 204552 KB Output is correct
21 Correct 1297 ms 209616 KB Output is correct
22 Correct 1313 ms 212424 KB Output is correct
23 Correct 1188 ms 178292 KB Output is correct
24 Correct 1008 ms 186308 KB Output is correct
25 Correct 1071 ms 200908 KB Output is correct
26 Correct 1054 ms 202260 KB Output is correct
27 Correct 1160 ms 208072 KB Output is correct
28 Correct 1284 ms 179496 KB Output is correct
29 Correct 1284 ms 179204 KB Output is correct
30 Correct 1288 ms 179264 KB Output is correct
31 Correct 1305 ms 179112 KB Output is correct
32 Correct 1335 ms 210044 KB Output is correct
33 Correct 1341 ms 183336 KB Output is correct
34 Correct 544 ms 131984 KB Output is correct
35 Correct 1474 ms 180624 KB Output is correct
36 Correct 1335 ms 183956 KB Output is correct
37 Correct 1437 ms 180112 KB Output is correct
38 Correct 1345 ms 182548 KB Output is correct
39 Correct 1384 ms 192460 KB Output is correct
40 Correct 1488 ms 180904 KB Output is correct
41 Correct 1226 ms 178928 KB Output is correct
42 Correct 1138 ms 182584 KB Output is correct
43 Correct 1479 ms 182652 KB Output is correct
44 Correct 1327 ms 179380 KB Output is correct
45 Correct 1234 ms 183144 KB Output is correct
46 Correct 1405 ms 192544 KB Output is correct
47 Correct 1286 ms 178756 KB Output is correct
48 Correct 1314 ms 178644 KB Output is correct
49 Correct 1326 ms 178756 KB Output is correct
50 Correct 1292 ms 178608 KB Output is correct
51 Correct 1396 ms 180592 KB Output is correct
52 Correct 1390 ms 180556 KB Output is correct