Submission #890156

# Submission time Handle Problem Language Result Execution time Memory
890156 2023-12-20T15:55:47 Z winter0101 Werewolf (IOI18_werewolf) C++14
100 / 100
541 ms 116640 KB
#include <bits/stdc++.h>
#include "werewolf.h"
using namespace std;
#define all(fl) fl.begin(),fl.end()
#define pb push_back
#define fi first
#define se second
#define for1(i,j,k) for(int i=j;i<=k;i++)
#define for2(i,j,k) for(int i=j;i>=k;i--)
#define for3(i,j,k,l) for(int i=j;i<=k;i+=l)
#define lb lower_bound
#define ub upper_bound
#define sz(a) (int)a.size()
#define pii pair<int,int>
#define pli pair<long long,int>
#define gcd __gcd
#define lcm(x,y) x*y/__gcd(x,y)
#define pil pair<int,long long>
const int maxn = 2e5 + 9;
struct DSU_Tree {
    vector<vector<int>>a;
    vector<int>f;
    int n;
    int fs(int u) {
        if (f[u] < 0)
            return u;

        return f[u] = fs(f[u]);
    }
    void unite(int u, int v) {
        u = fs(u), v = fs(v);

        if (u == v)
            return;

        n++;
        f[n] = f[u] + f[v];
        a[n].pb(u);
        a[n].pb(v);
        f[u] = n;
        f[v] = n;
    }
    int tme = 0;
    vector<int>in, out, rev;
    void dfs(int u) {
        in[u] = ++tme;
        rev[in[u]] = u;

        for (auto v : a[u]) {
            dfs(v);
        }

        out[u] = tme;
    }
    void resz(int _n) {
        n = _n;
        f.resize(2 * n + 9);
        a.resize(2 * n + 9);
        for1(i, 1, n)f[i] = -1;
        in.resize(2 * n + 9);
        out.resize(2 * n + 9);
        rev.resize(2 * n + 9);
    }
};
int st[maxn * 8];
void update(int id, int l, int r, int u, int val) {
    if (l > u || r < u)
        return;

    if (l == r) {
        st[id] = val;
        return;
    }

    int mid = (l + r) / 2;
    update(id * 2, l, mid, u, val);
    update(id * 2 + 1, mid + 1, r, u, val);
    st[id] = max(st[id * 2], st[id * 2 + 1]);
}
int get(int id, int l, int r, int u, int v) {
    if (l > v || r < u || u > v)
        return 0;

    if (u <= l && r <= v)
        return st[id];

    int mid = (l + r) / 2;
    return max(get(id * 2, l, mid, u, v), get(id * 2 + 1, mid + 1, r, u, v));
}
bool ans[maxn];
struct edg {
    int u, v;
} b[maxn * 2];
int pars[maxn], pare[maxn];
vector<int>ask1[maxn], ask2[maxn];
vector<int>canh[maxn];
vector<int>answer[maxn * 2];
bool valid[maxn];
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 m = sz(x), q = sz(S);
    for1(i, 0, m - 1)x[i]++, y[i]++;
    for1(i, 0, q - 1)S[i]++, E[i]++, L[i]++, R[i]++;
    for1(i, 1, m) {
        b[i] = {x[i - 1], y[i - 1]};
        canh[max(x[i - 1], y[i - 1])].pb(i);
    }
    for1(i, 0, q - 1)swap(S[i], E[i]);;
    DSU_Tree t1, t2; //t1 for 1->n t2 for n->1
    for1(i, 0, q - 1) {
        ask1[R[i]].pb(i);
    }
    t1.resz(n), t2.resz(n);
    for1(i, 1, n) {
        for (auto v : canh[i]) {
            t1.unite(b[v].u, b[v].v);
        }

        for (auto v : ask1[i]) {
            pars[v] = t1.fs(S[v]);
        }

        canh[i].clear();
    }
    for1(i, 1, m) {
        canh[min(x[i - 1], y[i - 1])].pb(i);
    }
    for1(i, 0, q - 1) {
        ask2[L[i]].pb(i);
    }
    for2(i, n, 1) {
        for (auto v : canh[i]) {
            t2.unite(b[v].u, b[v].v);
        }

        for (auto v : ask2[i]) {
            pare[v] = t2.fs(E[v]);
        }
    }
    t1.dfs(t1.n), t2.dfs(t2.n);
    int nn = t2.n;
    for1(i, 0, q - 1) {
        answer[t1.out[pars[i]]].pb(i);
    }
    for1(i, 1, t1.n) {
        if (t1.rev[i] <= n) {
            update(1, 1, nn, t2.in[t1.rev[i]], i);
        }

        for (auto v : answer[i]) {
            int start = pars[v], ed = pare[v];

            if (get(1, 1, nn, t2.in[ed], t2.out[ed]) >= t1.in[start]) {
                valid[v] = 1;
            }
        }
    }
    vector<int>last;
    for1(i, 0, q - 1)last.pb(valid[i]);
    return last;
}
# Verdict Execution time Memory Grader output
1 Correct 6 ms 29020 KB Output is correct
2 Correct 7 ms 29164 KB Output is correct
3 Correct 6 ms 29020 KB Output is correct
4 Correct 6 ms 29020 KB Output is correct
5 Correct 7 ms 29020 KB Output is correct
6 Correct 6 ms 29020 KB Output is correct
7 Correct 6 ms 29164 KB Output is correct
8 Correct 6 ms 29020 KB Output is correct
9 Correct 7 ms 29160 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 29020 KB Output is correct
2 Correct 7 ms 29164 KB Output is correct
3 Correct 6 ms 29020 KB Output is correct
4 Correct 6 ms 29020 KB Output is correct
5 Correct 7 ms 29020 KB Output is correct
6 Correct 6 ms 29020 KB Output is correct
7 Correct 6 ms 29164 KB Output is correct
8 Correct 6 ms 29020 KB Output is correct
9 Correct 7 ms 29160 KB Output is correct
10 Correct 10 ms 30300 KB Output is correct
11 Correct 11 ms 30300 KB Output is correct
12 Correct 10 ms 30300 KB Output is correct
13 Correct 10 ms 30196 KB Output is correct
14 Correct 10 ms 30300 KB Output is correct
15 Correct 11 ms 30384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 466 ms 110992 KB Output is correct
2 Correct 407 ms 112844 KB Output is correct
3 Correct 401 ms 111040 KB Output is correct
4 Correct 423 ms 110464 KB Output is correct
5 Correct 450 ms 110284 KB Output is correct
6 Correct 457 ms 110264 KB Output is correct
7 Correct 424 ms 108212 KB Output is correct
8 Correct 382 ms 112844 KB Output is correct
9 Correct 385 ms 110180 KB Output is correct
10 Correct 357 ms 108624 KB Output is correct
11 Correct 389 ms 109152 KB Output is correct
12 Correct 364 ms 109756 KB Output is correct
13 Correct 423 ms 113592 KB Output is correct
14 Correct 413 ms 113472 KB Output is correct
15 Correct 408 ms 113540 KB Output is correct
16 Correct 465 ms 113388 KB Output is correct
17 Correct 389 ms 107720 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 29020 KB Output is correct
2 Correct 7 ms 29164 KB Output is correct
3 Correct 6 ms 29020 KB Output is correct
4 Correct 6 ms 29020 KB Output is correct
5 Correct 7 ms 29020 KB Output is correct
6 Correct 6 ms 29020 KB Output is correct
7 Correct 6 ms 29164 KB Output is correct
8 Correct 6 ms 29020 KB Output is correct
9 Correct 7 ms 29160 KB Output is correct
10 Correct 10 ms 30300 KB Output is correct
11 Correct 11 ms 30300 KB Output is correct
12 Correct 10 ms 30300 KB Output is correct
13 Correct 10 ms 30196 KB Output is correct
14 Correct 10 ms 30300 KB Output is correct
15 Correct 11 ms 30384 KB Output is correct
16 Correct 466 ms 110992 KB Output is correct
17 Correct 407 ms 112844 KB Output is correct
18 Correct 401 ms 111040 KB Output is correct
19 Correct 423 ms 110464 KB Output is correct
20 Correct 450 ms 110284 KB Output is correct
21 Correct 457 ms 110264 KB Output is correct
22 Correct 424 ms 108212 KB Output is correct
23 Correct 382 ms 112844 KB Output is correct
24 Correct 385 ms 110180 KB Output is correct
25 Correct 357 ms 108624 KB Output is correct
26 Correct 389 ms 109152 KB Output is correct
27 Correct 364 ms 109756 KB Output is correct
28 Correct 423 ms 113592 KB Output is correct
29 Correct 413 ms 113472 KB Output is correct
30 Correct 408 ms 113540 KB Output is correct
31 Correct 465 ms 113388 KB Output is correct
32 Correct 389 ms 107720 KB Output is correct
33 Correct 541 ms 111544 KB Output is correct
34 Correct 207 ms 61912 KB Output is correct
35 Correct 490 ms 113868 KB Output is correct
36 Correct 436 ms 111624 KB Output is correct
37 Correct 485 ms 113176 KB Output is correct
38 Correct 455 ms 112060 KB Output is correct
39 Correct 436 ms 116172 KB Output is correct
40 Correct 497 ms 115764 KB Output is correct
41 Correct 425 ms 112016 KB Output is correct
42 Correct 378 ms 109268 KB Output is correct
43 Correct 524 ms 116640 KB Output is correct
44 Correct 482 ms 112444 KB Output is correct
45 Correct 414 ms 115860 KB Output is correct
46 Correct 407 ms 115412 KB Output is correct
47 Correct 448 ms 113648 KB Output is correct
48 Correct 488 ms 113328 KB Output is correct
49 Correct 415 ms 113704 KB Output is correct
50 Correct 442 ms 113360 KB Output is correct
51 Correct 453 ms 114128 KB Output is correct
52 Correct 437 ms 114180 KB Output is correct