Submission #600093

# Submission time Handle Problem Language Result Execution time Memory
600093 2022-07-20T12:57:42 Z MohamedFaresNebili Werewolf (IOI18_werewolf) C++14
100 / 100
713 ms 87780 KB
#include <bits/stdc++.h>
#include "werewolf.h"
/// #pragma GCC optimize ("Ofast")
/// #pragma GCC target ("avx2")
/// #pragma GCC optimize("unroll-loops")

                using namespace std;

                using ll = long long;
                using ld = long double;
                using ii = pair<ll, ll>;
                using vi = vector<int>;

                #define ff first
                #define ss second
                #define pb push_back
                #define all(x) (x).begin(), (x).end()
                #define lb lower_bound

                const int MOD = 1e9 + 7;

                int P[200005][2];
                int W[200005], timer;
                vector<int> adj[200005];
                vector<int> G[200005][2];
                vector<int> A[200005], B[200005];
                int tin[200005][2], out[200005][2];
                int st[800005], D[200005], K[200005];

                int query(int v, int l, int r, int lo, int hi) {
                    if(l > hi || r < lo) return 0;
                    if(l >= lo && r <= hi) return st[v];
                    return query(v * 2, l, (l + r) / 2, lo, hi)
                        +  query(v * 2 + 1, (l + r) / 2 + 1, r, lo, hi);
                }
                void update(int v, int l, int r, int p) {
                    if(l == r) {
                        st[v]++;
                        return;
                    }
                    int md = (l + r) / 2;
                    if(p <= md) update(v * 2, l, md, p);
                    else update(v * 2 + 1, md + 1, r, p);
                    st[v] = st[v * 2] + st[v * 2 + 1];
                }
                int findSet(int v, int s) {
                    if(P[v][s] == v) return v;
                    return P[v][s] = findSet(P[v][s], s);
                }
                void unionSet(int u, int v, int s) {
                    u = findSet(u, s), v = findSet(v, s);
                    if(u == v) return;
                    P[v][s] = u;
                }
                void dfs(int v, int p) {
                    tin[v][p] = timer++;
                    for(auto u : G[v][p])
                        dfs(u, p);
                    out[v][p] = timer - 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) {
                    int M = X.size(), Q = S.size();
                    for(int l = 0; l < N; l++)
                        P[l][0] = P[l][1] = l;
                    for(int l = 0; l < M; l++) {
                        int U = X[l], V = Y[l];
                        adj[U].push_back(V);
                        adj[V].push_back(U);
                    }
                    for(int l = 0; l < Q; l++) {
                        A[L[l]].push_back(l);
                        B[R[l]].push_back(l);
                    }
                    for(int l = N - 1; l >= 0; l--) {
                        for(auto u : adj[l]) {
                            if(u < l || findSet(u, 0) == l) continue;
                            G[l][0].push_back(findSet(u, 0));
                            unionSet(l, u, 0);
                        }
                        for(auto u : A[l]) D[u] = findSet(S[u], 0);
                    }
                    for(int l = 0; l < N; l++) {
                        for(auto u : adj[l]) {
                            if(u > l || findSet(u, 1) == l) continue;
                            G[l][1].push_back(findSet(u, 1));
                            unionSet(l, u, 1);
                        }
                        for(auto u : B[l]) K[u] = findSet(E[u], 1);
                    }
                    dfs(0, 0); timer = 0; dfs(N - 1, 1);
                    vector<int> Qr[N];
                    vector<int> res(Q, 0);

                    for(int l = 0; l < Q; l++) {
                        int v = D[l];
                        Qr[tin[v][0]].push_back(-l - 1);
                        Qr[out[v][0]].push_back(l);
                    }
                    for(int l = 0; l < N; l++) {
                        W[tin[l][0]] = tin[l][1];
                    }
                    for(int l = 0; l < N; l++) {
                        for(auto u : Qr[l]) {
                            if(u >= 0) continue;
                            int v = -u - 1; int C = K[v];
                            res[v] -= query(1, 0, N - 1, tin[C][1], out[C][1]);
                        }
                        update(1, 0, N - 1, W[l]);
                        for(auto u : Qr[l]) {
                            if(u < 0) continue;
                            int C = K[u];
                            res[u] += query(1, 0, N - 1, tin[C][1], out[C][1]);
                        }
                    }
                    for(int l = 0; l < Q; l++)
                        res[l] = min(res[l], 1);
                    return res;
                }
# Verdict Execution time Memory Grader output
1 Correct 11 ms 23764 KB Output is correct
2 Correct 13 ms 23800 KB Output is correct
3 Correct 12 ms 23808 KB Output is correct
4 Correct 12 ms 23764 KB Output is correct
5 Correct 12 ms 23808 KB Output is correct
6 Correct 12 ms 23800 KB Output is correct
7 Correct 14 ms 23808 KB Output is correct
8 Correct 11 ms 23796 KB Output is correct
9 Correct 12 ms 23764 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 23764 KB Output is correct
2 Correct 13 ms 23800 KB Output is correct
3 Correct 12 ms 23808 KB Output is correct
4 Correct 12 ms 23764 KB Output is correct
5 Correct 12 ms 23808 KB Output is correct
6 Correct 12 ms 23800 KB Output is correct
7 Correct 14 ms 23808 KB Output is correct
8 Correct 11 ms 23796 KB Output is correct
9 Correct 12 ms 23764 KB Output is correct
10 Correct 17 ms 24660 KB Output is correct
11 Correct 17 ms 24580 KB Output is correct
12 Correct 16 ms 24660 KB Output is correct
13 Correct 17 ms 24768 KB Output is correct
14 Correct 18 ms 24776 KB Output is correct
15 Correct 19 ms 24708 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 656 ms 81484 KB Output is correct
2 Correct 550 ms 79892 KB Output is correct
3 Correct 546 ms 79356 KB Output is correct
4 Correct 547 ms 79668 KB Output is correct
5 Correct 556 ms 79988 KB Output is correct
6 Correct 579 ms 80940 KB Output is correct
7 Correct 528 ms 77936 KB Output is correct
8 Correct 588 ms 79768 KB Output is correct
9 Correct 525 ms 77912 KB Output is correct
10 Correct 414 ms 77836 KB Output is correct
11 Correct 428 ms 78024 KB Output is correct
12 Correct 514 ms 78528 KB Output is correct
13 Correct 566 ms 84920 KB Output is correct
14 Correct 518 ms 84920 KB Output is correct
15 Correct 511 ms 84864 KB Output is correct
16 Correct 541 ms 85028 KB Output is correct
17 Correct 477 ms 77888 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 23764 KB Output is correct
2 Correct 13 ms 23800 KB Output is correct
3 Correct 12 ms 23808 KB Output is correct
4 Correct 12 ms 23764 KB Output is correct
5 Correct 12 ms 23808 KB Output is correct
6 Correct 12 ms 23800 KB Output is correct
7 Correct 14 ms 23808 KB Output is correct
8 Correct 11 ms 23796 KB Output is correct
9 Correct 12 ms 23764 KB Output is correct
10 Correct 17 ms 24660 KB Output is correct
11 Correct 17 ms 24580 KB Output is correct
12 Correct 16 ms 24660 KB Output is correct
13 Correct 17 ms 24768 KB Output is correct
14 Correct 18 ms 24776 KB Output is correct
15 Correct 19 ms 24708 KB Output is correct
16 Correct 656 ms 81484 KB Output is correct
17 Correct 550 ms 79892 KB Output is correct
18 Correct 546 ms 79356 KB Output is correct
19 Correct 547 ms 79668 KB Output is correct
20 Correct 556 ms 79988 KB Output is correct
21 Correct 579 ms 80940 KB Output is correct
22 Correct 528 ms 77936 KB Output is correct
23 Correct 588 ms 79768 KB Output is correct
24 Correct 525 ms 77912 KB Output is correct
25 Correct 414 ms 77836 KB Output is correct
26 Correct 428 ms 78024 KB Output is correct
27 Correct 514 ms 78528 KB Output is correct
28 Correct 566 ms 84920 KB Output is correct
29 Correct 518 ms 84920 KB Output is correct
30 Correct 511 ms 84864 KB Output is correct
31 Correct 541 ms 85028 KB Output is correct
32 Correct 477 ms 77888 KB Output is correct
33 Correct 632 ms 81096 KB Output is correct
34 Correct 263 ms 60608 KB Output is correct
35 Correct 713 ms 82080 KB Output is correct
36 Correct 619 ms 81724 KB Output is correct
37 Correct 681 ms 81632 KB Output is correct
38 Correct 634 ms 82136 KB Output is correct
39 Correct 604 ms 87780 KB Output is correct
40 Correct 578 ms 86460 KB Output is correct
41 Correct 569 ms 79692 KB Output is correct
42 Correct 484 ms 77972 KB Output is correct
43 Correct 688 ms 85184 KB Output is correct
44 Correct 578 ms 80292 KB Output is correct
45 Correct 461 ms 84256 KB Output is correct
46 Correct 495 ms 84456 KB Output is correct
47 Correct 534 ms 85152 KB Output is correct
48 Correct 534 ms 84916 KB Output is correct
49 Correct 525 ms 85056 KB Output is correct
50 Correct 509 ms 84980 KB Output is correct
51 Correct 569 ms 83528 KB Output is correct
52 Correct 541 ms 83616 KB Output is correct