답안 #1037441

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1037441 2024-07-28T21:30:06 Z c2zi6 늑대인간 (IOI18_werewolf) C++14
100 / 100
570 ms 106160 KB
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define replr(i, a, b) for (int i = int(a); i <= int(b); ++i)
#define reprl(i, a, b) for (int i = int(a); i >= int(b); --i)
#define rep(i, n) for (int i = 0; i < int(n); ++i)
#define mkp(a, b) make_pair(a, b)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<PII> VPI;
typedef vector<VI> VVI;
typedef vector<VVI> VVVI;
typedef vector<VPI> VVPI;
typedef pair<ll, ll> PLL;
typedef vector<ll> VL;
typedef vector<PLL> VPL;
typedef vector<VL> VVL;
typedef vector<VVL> VVVL;
typedef vector<VPL> VVPL;
template<class T> T setmax(T& a, T b) {if (a < b) return a = b; return a;}
template<class T> T setmin(T& a, T b) {if (a < b) return a; return a = b;}
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template<class T>
using indset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#include "werewolf.h"

struct DSU {
    int n;
    VI par;
    DSU(){}
    DSU(int n_arg) : n(n_arg) {
        par = VI(n);
        rep(u, n) par[u] = u;
    }
    int get(int u) {
        return u == par[u] ? u : (par[u] = get(par[u]));
    }
    bool onion(int u, int v) {
        u = get(u);
        v = get(v);
        if (u == v) return false;
        par[v] = u;
        return true;
    }
} dsu;

struct COMPTREE {
    int n;
    VVI par;
    VVI gp;
    VI tin, tout;
    VI euler;
    int tc;
    COMPTREE(){}
    COMPTREE(int n_arg) : n(n_arg) {
        par = VVI(n, VI(20, -1));
        gp = VVI(n);
        tin = tout = VI(n);
    }
    void dfs(int u) {
        euler.pb(u);
        tin[u] = tc++;
        for (int v : gp[u]) dfs(v);
        tout[u] = tc-1;
    }
    void init() {
        replr(i, 1, 19) rep(u, n) par[u][i] = par[par[u][i-1]][i-1];
        int root;
        rep(u, n) {
            if (par[u][0] == u) root = u;
            else gp[par[u][0]].pb(u);
        }
        tc = 0;
        dfs(root);
    }
    int lift(int u, int L, int R) {
        reprl(i, 19, 0) if (L <= par[u][i] && par[u][i] <= R) u = par[u][i];
        return u;
    }
} lwp, hgp;

struct QUERY {
    int ind, al, ar, bl, br;
};
bool operator<(const QUERY& a, const QUERY& b) {
    return a.ar < b.ar;
}

struct SEGTREE {
    int n;
    VI tree;
    SEGTREE(int sz) {
        n = 1;
        while (n < sz) n *= 2;
        tree = VI(2*n, -1);
    }
    void set(int N, int L, int R, int i, int s) {
        if (i < L || i > R) return;
        if (L == R) {
            tree[N] = s;
            return;
        }
        int M = (L + R) / 2;
        set(2*N+1, L, M, i, s);
        set(2*N+2, M+1, R, i, s);
        tree[N] = max(tree[2*N+1], tree[2*N+2]);
    }
    int get(int N, int L, int R, int l, int r) {
        if (l <= L && R <= r) return tree[N];
        if (R < l || L > r) return -1;
        int M = (L + R) / 2;
        return max(get(2*N+1, L, M, l, r), get(2*N+2, M+1, R, l, r));
    }
    void set(int i, int s) {
        set(0, 0, n-1, i, s);
    }
    int get(int l, int r) {
        return get(0, 0, n-1, l, r);
    }
};

VI check_validity(int N, VI X, VI Y, VI S, VI E, VI L, VI R) {
    int n = N;
    VVI gp(n);
    rep(i, X.size()) {
        gp[X[i]].pb(Y[i]);
        gp[Y[i]].pb(X[i]);
    }
    lwp = hgp = COMPTREE(n);
    dsu = DSU(n);
    replr(u, 0, n-1) for (int v : gp[u]) if (v < u) {
        if (dsu.onion(u, v = dsu.get(v))) lwp.par[v][0] = u;
    }
    lwp.par[n-1][0] = n-1;
    lwp.init();
    dsu = DSU(n);
    reprl(u, n-1, 0) for (int v : gp[u]) if (v > u) {
        if (dsu.onion(u, v = dsu.get(v))) hgp.par[v][0] = u;
    }
    hgp.par[0][0] = 0;
    hgp.init();
    vector<QUERY> qrs;
    rep(i, S.size()) {
        auto[u, v] = mkp(hgp.lift(S[i], L[i], +2e9), lwp.lift(E[i], -2e9, R[i]));
        qrs.pb({i, hgp.tin[u], hgp.tout[u], lwp.tin[v], lwp.tout[v]});
    }
    sort(all(qrs));
    VI ans(S.size());
    int ptr = 0;
    SEGTREE ds(n);
    for (auto[ind, al, ar, bl, br] : qrs) {
        while (ptr <= ar) ds.set(lwp.tin[hgp.euler[ptr]], ptr), ptr++;
        ans[ind] = (ds.get(bl, br) >= al);
    }
    return ans;
}






Compilation message

werewolf.cpp: In function 'VI check_validity(int, VI, VI, VI, VI, VI, VI)':
werewolf.cpp:151:13: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
  151 |         auto[u, v] = mkp(hgp.lift(S[i], L[i], +2e9), lwp.lift(E[i], -2e9, R[i]));
      |             ^
werewolf.cpp:158:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
  158 |     for (auto[ind, al, ar, bl, br] : qrs) {
      |              ^
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 4 ms 1884 KB Output is correct
11 Correct 4 ms 1800 KB Output is correct
12 Correct 4 ms 1884 KB Output is correct
13 Correct 5 ms 1884 KB Output is correct
14 Correct 5 ms 1884 KB Output is correct
15 Correct 5 ms 1880 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 429 ms 98424 KB Output is correct
2 Correct 431 ms 101040 KB Output is correct
3 Correct 415 ms 99196 KB Output is correct
4 Correct 401 ms 98484 KB Output is correct
5 Correct 386 ms 98684 KB Output is correct
6 Correct 427 ms 98792 KB Output is correct
7 Correct 358 ms 98484 KB Output is correct
8 Correct 435 ms 100276 KB Output is correct
9 Correct 341 ms 99248 KB Output is correct
10 Correct 314 ms 98224 KB Output is correct
11 Correct 352 ms 98732 KB Output is correct
12 Correct 318 ms 98660 KB Output is correct
13 Correct 460 ms 105272 KB Output is correct
14 Correct 444 ms 104892 KB Output is correct
15 Correct 483 ms 105596 KB Output is correct
16 Correct 535 ms 104892 KB Output is correct
17 Correct 353 ms 97972 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 4 ms 1884 KB Output is correct
11 Correct 4 ms 1800 KB Output is correct
12 Correct 4 ms 1884 KB Output is correct
13 Correct 5 ms 1884 KB Output is correct
14 Correct 5 ms 1884 KB Output is correct
15 Correct 5 ms 1880 KB Output is correct
16 Correct 429 ms 98424 KB Output is correct
17 Correct 431 ms 101040 KB Output is correct
18 Correct 415 ms 99196 KB Output is correct
19 Correct 401 ms 98484 KB Output is correct
20 Correct 386 ms 98684 KB Output is correct
21 Correct 427 ms 98792 KB Output is correct
22 Correct 358 ms 98484 KB Output is correct
23 Correct 435 ms 100276 KB Output is correct
24 Correct 341 ms 99248 KB Output is correct
25 Correct 314 ms 98224 KB Output is correct
26 Correct 352 ms 98732 KB Output is correct
27 Correct 318 ms 98660 KB Output is correct
28 Correct 460 ms 105272 KB Output is correct
29 Correct 444 ms 104892 KB Output is correct
30 Correct 483 ms 105596 KB Output is correct
31 Correct 535 ms 104892 KB Output is correct
32 Correct 353 ms 97972 KB Output is correct
33 Correct 430 ms 98328 KB Output is correct
34 Correct 181 ms 25544 KB Output is correct
35 Correct 459 ms 100616 KB Output is correct
36 Correct 389 ms 99248 KB Output is correct
37 Correct 471 ms 99508 KB Output is correct
38 Correct 391 ms 99504 KB Output is correct
39 Correct 419 ms 105396 KB Output is correct
40 Correct 570 ms 106108 KB Output is correct
41 Correct 378 ms 100532 KB Output is correct
42 Correct 333 ms 99248 KB Output is correct
43 Correct 562 ms 104016 KB Output is correct
44 Correct 432 ms 99532 KB Output is correct
45 Correct 438 ms 105908 KB Output is correct
46 Correct 450 ms 105652 KB Output is correct
47 Correct 478 ms 105504 KB Output is correct
48 Correct 467 ms 105348 KB Output is correct
49 Correct 455 ms 105372 KB Output is correct
50 Correct 500 ms 105332 KB Output is correct
51 Correct 492 ms 105356 KB Output is correct
52 Correct 486 ms 106160 KB Output is correct