Submission #837421

# Submission time Handle Problem Language Result Execution time Memory
837421 2023-08-25T10:41:40 Z becaido Werewolf (IOI18_werewolf) C++17
100 / 100
591 ms 97424 KB
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx,popcnt,sse4,abm")
#include <bits/stdc++.h>
#include "werewolf.h"
using namespace std;

#define ll long long
#define Waimai ios::sync_with_stdio(false), cin.tie(0)
#define FOR(x,a,b) for(int x = a, I = b; x <= I; x++)
#define pb emplace_back
#define F first
#define S second

const int SIZE = 2e5 + 5;
const int H = __lg(SIZE);

int n, m, q;
vector<int> ans, adj[SIZE];
vector<pair<int, int>> ask[SIZE];

struct DSU {
    int to[SIZE];
    DSU() = default;
    void init() {
        iota(to, to + n, 0);
    }
    int dsu(int x) {
        return x == to[x] ? x : (to[x] = dsu(to[x]));
    }
};

struct Tree {
    vector<int> adj[SIZE];
    int root, to[SIZE][H + 1], h[SIZE];
    int dfsid, in[SIZE], out[SIZE], w[SIZE];
    DSU dsu;
    Tree() = default;
    void init() {
        dfsid = -1;
        dsu.init();
    }
    void add(int a, int b) {
        a = dsu.dsu(a), b = dsu.dsu(b);
        if (a == b) return;
        adj[a].pb(b);
        dsu.to[b] = a;
        root = a;
    }
    void build() {
        auto dfs = [&](auto dfs, int pos)->void {
            in[pos] = ++dfsid;
            w[pos] = 1;
            for (int np : adj[pos]) {
                h[np] = h[pos] + 1;
                to[np][0] = pos;
                dfs(dfs, np);
                w[pos] += w[np];
            }
            out[pos] = dfsid;
        };
        to[root][0] = root;
        dfs(dfs, root);
        FOR (j, 1, H) FOR (i, 0, n - 1) to[i][j] = to[to[i][j - 1]][j - 1];
    }
    int sch(int pos, int lim, int ty) {
        for (int i = H; i >= 0; i--) if ((ty == 1 && to[pos][i] >= lim) || (ty == 2 && to[pos][i] <= lim)) pos = to[pos][i];
        return pos;
    }
} t1, t2;

int a[SIZE], bit[SIZE];
void upd(int pos, int x) {
    for (pos++; pos <= n; pos += pos & -pos) bit[pos] += x;
}
int que(int pos) {
    int re = 0;
    for (pos++; pos; pos -= pos & -pos) re += bit[pos];
    return re;
}
int que(int l, int r) {
    return que(r) - que(l - 1);
}

vector<int> check_validity(int N, vector<int> X, vector<int> Y, vector<int> S, vector<int> E, vector<int> L, vector<int> R) {
    n = N, m = X.size(), q = S.size();
    ans.resize(q);
    FOR (i, 0, m - 1) {
        adj[X[i]].pb(Y[i]);
        adj[Y[i]].pb(X[i]);
    }
    t1.init(), t2.init();
    for (int i = n - 1; i >= 0; i--) for (int j : adj[i]) if (i < j) t1.add(i, j);
    FOR (i, 0, n - 1) for (int j : adj[i]) if (i > j) t2.add(i, j);
    t1.build(), t2.build();
    FOR (i, 0, n - 1) a[t1.in[i]] = i;
    FOR (i, 0, q - 1) {
        S[i] = t1.sch(S[i], L[i], 1);
        E[i] = t2.sch(E[i], R[i], 2);
        ask[t1.out[S[i]]].pb(i, 1);
        if (t1.in[S[i]]) ask[t1.in[S[i]] - 1].pb(i, -1);
    }
    FOR (i, 0, n - 1) {
        upd(t2.in[a[i]], 1);
        for (auto [id, coef] : ask[i]) ans[id] += coef * que(t2.in[E[id]], t2.out[E[id]]);
    }
    FOR (i, 0, q - 1) ans[i] = ans[i] > 0;
    return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 9 ms 19156 KB Output is correct
2 Correct 8 ms 19156 KB Output is correct
3 Correct 12 ms 19188 KB Output is correct
4 Correct 12 ms 19160 KB Output is correct
5 Correct 9 ms 19156 KB Output is correct
6 Correct 9 ms 19156 KB Output is correct
7 Correct 11 ms 19116 KB Output is correct
8 Correct 11 ms 19092 KB Output is correct
9 Correct 9 ms 19156 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 19156 KB Output is correct
2 Correct 8 ms 19156 KB Output is correct
3 Correct 12 ms 19188 KB Output is correct
4 Correct 12 ms 19160 KB Output is correct
5 Correct 9 ms 19156 KB Output is correct
6 Correct 9 ms 19156 KB Output is correct
7 Correct 11 ms 19116 KB Output is correct
8 Correct 11 ms 19092 KB Output is correct
9 Correct 9 ms 19156 KB Output is correct
10 Correct 12 ms 20180 KB Output is correct
11 Correct 12 ms 20184 KB Output is correct
12 Correct 11 ms 20180 KB Output is correct
13 Correct 14 ms 20304 KB Output is correct
14 Correct 15 ms 20456 KB Output is correct
15 Correct 13 ms 20308 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 459 ms 88212 KB Output is correct
2 Correct 509 ms 89876 KB Output is correct
3 Correct 443 ms 87824 KB Output is correct
4 Correct 346 ms 86804 KB Output is correct
5 Correct 397 ms 86940 KB Output is correct
6 Correct 399 ms 87828 KB Output is correct
7 Correct 440 ms 86616 KB Output is correct
8 Correct 407 ms 89896 KB Output is correct
9 Correct 378 ms 86524 KB Output is correct
10 Correct 311 ms 86432 KB Output is correct
11 Correct 325 ms 86268 KB Output is correct
12 Correct 278 ms 85860 KB Output is correct
13 Correct 519 ms 95368 KB Output is correct
14 Correct 457 ms 95340 KB Output is correct
15 Correct 451 ms 95332 KB Output is correct
16 Correct 502 ms 95352 KB Output is correct
17 Correct 406 ms 86780 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 19156 KB Output is correct
2 Correct 8 ms 19156 KB Output is correct
3 Correct 12 ms 19188 KB Output is correct
4 Correct 12 ms 19160 KB Output is correct
5 Correct 9 ms 19156 KB Output is correct
6 Correct 9 ms 19156 KB Output is correct
7 Correct 11 ms 19116 KB Output is correct
8 Correct 11 ms 19092 KB Output is correct
9 Correct 9 ms 19156 KB Output is correct
10 Correct 12 ms 20180 KB Output is correct
11 Correct 12 ms 20184 KB Output is correct
12 Correct 11 ms 20180 KB Output is correct
13 Correct 14 ms 20304 KB Output is correct
14 Correct 15 ms 20456 KB Output is correct
15 Correct 13 ms 20308 KB Output is correct
16 Correct 459 ms 88212 KB Output is correct
17 Correct 509 ms 89876 KB Output is correct
18 Correct 443 ms 87824 KB Output is correct
19 Correct 346 ms 86804 KB Output is correct
20 Correct 397 ms 86940 KB Output is correct
21 Correct 399 ms 87828 KB Output is correct
22 Correct 440 ms 86616 KB Output is correct
23 Correct 407 ms 89896 KB Output is correct
24 Correct 378 ms 86524 KB Output is correct
25 Correct 311 ms 86432 KB Output is correct
26 Correct 325 ms 86268 KB Output is correct
27 Correct 278 ms 85860 KB Output is correct
28 Correct 519 ms 95368 KB Output is correct
29 Correct 457 ms 95340 KB Output is correct
30 Correct 451 ms 95332 KB Output is correct
31 Correct 502 ms 95352 KB Output is correct
32 Correct 406 ms 86780 KB Output is correct
33 Correct 459 ms 88576 KB Output is correct
34 Correct 264 ms 43424 KB Output is correct
35 Correct 539 ms 90840 KB Output is correct
36 Correct 514 ms 88724 KB Output is correct
37 Correct 471 ms 90084 KB Output is correct
38 Correct 591 ms 89240 KB Output is correct
39 Correct 452 ms 97424 KB Output is correct
40 Correct 560 ms 94004 KB Output is correct
41 Correct 414 ms 88352 KB Output is correct
42 Correct 358 ms 86188 KB Output is correct
43 Correct 442 ms 94004 KB Output is correct
44 Correct 419 ms 89296 KB Output is correct
45 Correct 319 ms 95524 KB Output is correct
46 Correct 322 ms 95752 KB Output is correct
47 Correct 438 ms 95388 KB Output is correct
48 Correct 520 ms 95360 KB Output is correct
49 Correct 549 ms 95432 KB Output is correct
50 Correct 483 ms 95288 KB Output is correct
51 Correct 434 ms 93500 KB Output is correct
52 Correct 419 ms 93600 KB Output is correct