Submission #393327

# Submission time Handle Problem Language Result Execution time Memory
393327 2021-04-23T07:59:09 Z BartolM Werewolf (IOI18_werewolf) C++17
100 / 100
1033 ms 110764 KB
#define DEBUG 0
#include <bits/stdc++.h>

using namespace std;

#define X first
#define Y second
#define mp make_pair
#define pb push_back
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <int, pii> pip;
typedef pair <pii, int> ppi;
typedef pair <ll, ll> pll;
typedef pair <pii, pii> ppp;

const int INF=0x3f3f3f3f;
const int N=2e5+5;

int n, m, q, uk, dt;
int P[2*N], roots[N], lef[2*N], rig[2*N], F[2*N];
vector <int> ls[N], dj[2*N], toc[2*N], sol;
vector <pii> que[N];
vector <ppp> duz[2*N];
pii p[N], r_x[N], r_y[N];

int query(int x) {
    int ret=0;
    for (x++; x>0; x-=x&-x) ret+=F[x];
    return ret;
}

void update(int x, int val) {
    for (x++; x<=2*n+2; x+=x&-x) F[x]+=val;
}

int name(int x) {
    if (x==P[x]) return x;
    P[x]=name(P[x]);
    return P[x];
}

void dfs(int node) {
    lef[node]=dt++;
    for (int sus:dj[node]) dfs(sus);
    rig[node]=dt-1;
}

vector<int> check_validity(int NN, vector<int> XX, vector<int> YY,
                                vector<int> S, vector<int> E,
                                vector<int> L, vector<int> R) {
    n=NN;
    m=XX.size();
    q=L.size();
    for (int i=0; i<m; ++i) ls[XX[i]].pb(YY[i]), ls[YY[i]].pb(XX[i]);

    for (int i=0; i<2*n; ++i) P[i]=i;
    for (int i=0; i<q; ++i) que[L[i]].pb(mp(S[i], i));
    uk=n;
    for (int i=n-1; i>=0; --i) {
        dj[uk].pb(name(i));
        #if DEBUG
            printf("dijete od %d je %d\n", uk, name(i));
        #endif // DEBUG
        P[name(i)]=uk;
        for (int sus:ls[i]) {
            if (sus<=i || name(sus)==uk) continue;
            #if DEBUG
                printf("dijete od %d je %d\n", uk, name(sus));
            #endif // DEBUG
            dj[uk].pb(name(sus));
            P[name(sus)]=uk;
        }
        uk++;
        for (pii pp:que[i]) roots[pp.Y]=name(pp.X);
    }
    dt=0;
    dfs(name(0));
    for (int i=0; i<n; ++i) p[i].X=lef[i];
    for (int i=0; i<q; ++i) r_x[i]=mp(lef[roots[i]], rig[roots[i]]);

    for (int i=0; i<n; ++i) que[i].clear();
    for (int i=0; i<2*n; ++i) dj[i].clear(), P[i]=i;
    for (int i=0; i<q; ++i) que[R[i]].pb(mp(E[i], i));
    uk=n, dt=0;

    for (int i=0; i<n; ++i) {
        dj[uk].pb(name(i));
        P[name(i)]=uk;
        for (int sus:ls[i]) {
            if (sus>=i || name(sus)==uk) continue;
            dj[uk].pb(name(sus));
            P[name(sus)]=uk;
        }
        uk++;
        for (pii pp:que[i]) roots[pp.Y]=name(pp.X);
    }
    dfs(name(0));
    for (int i=0; i<n; ++i) {
        p[i].Y=lef[i];
        toc[p[i].X].pb(p[i].Y);
    }
    for (int i=0; i<q; ++i) {
        r_y[i]=mp(lef[roots[i]], rig[roots[i]]);
        if (r_x[i].X) duz[r_x[i].X-1].pb(mp(r_y[i], mp(-1, i)));
        duz[r_x[i].Y].pb(mp(r_y[i], mp(1, i)));
    }
    sol.resize(q, 0);
    for (int i=0; i<2*n; ++i) {
        for (int y:toc[i]) update(y, 1);
        for (ppp pp:duz[i]) sol[pp.Y.Y]+=(query(pp.X.Y)-query(pp.X.X-1))*pp.Y.X;
    }
    for (int i=0; i<q; ++i) sol[i]=!!sol[i];
    return sol;
}

# Verdict Execution time Memory Grader output
1 Correct 22 ms 37836 KB Output is correct
2 Correct 27 ms 37884 KB Output is correct
3 Correct 26 ms 37836 KB Output is correct
4 Correct 22 ms 37920 KB Output is correct
5 Correct 23 ms 37888 KB Output is correct
6 Correct 22 ms 37940 KB Output is correct
7 Correct 23 ms 37836 KB Output is correct
8 Correct 22 ms 37824 KB Output is correct
9 Correct 22 ms 37900 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 22 ms 37836 KB Output is correct
2 Correct 27 ms 37884 KB Output is correct
3 Correct 26 ms 37836 KB Output is correct
4 Correct 22 ms 37920 KB Output is correct
5 Correct 23 ms 37888 KB Output is correct
6 Correct 22 ms 37940 KB Output is correct
7 Correct 23 ms 37836 KB Output is correct
8 Correct 22 ms 37824 KB Output is correct
9 Correct 22 ms 37900 KB Output is correct
10 Correct 27 ms 38832 KB Output is correct
11 Correct 27 ms 38816 KB Output is correct
12 Correct 26 ms 38696 KB Output is correct
13 Correct 30 ms 38860 KB Output is correct
14 Correct 32 ms 38788 KB Output is correct
15 Correct 34 ms 38800 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 765 ms 95696 KB Output is correct
2 Correct 598 ms 97620 KB Output is correct
3 Correct 585 ms 95780 KB Output is correct
4 Correct 555 ms 93996 KB Output is correct
5 Correct 635 ms 94320 KB Output is correct
6 Correct 731 ms 95692 KB Output is correct
7 Correct 655 ms 92520 KB Output is correct
8 Correct 589 ms 97564 KB Output is correct
9 Correct 543 ms 92832 KB Output is correct
10 Correct 511 ms 93580 KB Output is correct
11 Correct 517 ms 93620 KB Output is correct
12 Correct 648 ms 93372 KB Output is correct
13 Correct 587 ms 97400 KB Output is correct
14 Correct 595 ms 97360 KB Output is correct
15 Correct 543 ms 97408 KB Output is correct
16 Correct 658 ms 97420 KB Output is correct
17 Correct 664 ms 92480 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 22 ms 37836 KB Output is correct
2 Correct 27 ms 37884 KB Output is correct
3 Correct 26 ms 37836 KB Output is correct
4 Correct 22 ms 37920 KB Output is correct
5 Correct 23 ms 37888 KB Output is correct
6 Correct 22 ms 37940 KB Output is correct
7 Correct 23 ms 37836 KB Output is correct
8 Correct 22 ms 37824 KB Output is correct
9 Correct 22 ms 37900 KB Output is correct
10 Correct 27 ms 38832 KB Output is correct
11 Correct 27 ms 38816 KB Output is correct
12 Correct 26 ms 38696 KB Output is correct
13 Correct 30 ms 38860 KB Output is correct
14 Correct 32 ms 38788 KB Output is correct
15 Correct 34 ms 38800 KB Output is correct
16 Correct 765 ms 95696 KB Output is correct
17 Correct 598 ms 97620 KB Output is correct
18 Correct 585 ms 95780 KB Output is correct
19 Correct 555 ms 93996 KB Output is correct
20 Correct 635 ms 94320 KB Output is correct
21 Correct 731 ms 95692 KB Output is correct
22 Correct 655 ms 92520 KB Output is correct
23 Correct 589 ms 97564 KB Output is correct
24 Correct 543 ms 92832 KB Output is correct
25 Correct 511 ms 93580 KB Output is correct
26 Correct 517 ms 93620 KB Output is correct
27 Correct 648 ms 93372 KB Output is correct
28 Correct 587 ms 97400 KB Output is correct
29 Correct 595 ms 97360 KB Output is correct
30 Correct 543 ms 97408 KB Output is correct
31 Correct 658 ms 97420 KB Output is correct
32 Correct 664 ms 92480 KB Output is correct
33 Correct 820 ms 104876 KB Output is correct
34 Correct 331 ms 85268 KB Output is correct
35 Correct 719 ms 106896 KB Output is correct
36 Correct 777 ms 104440 KB Output is correct
37 Correct 729 ms 106296 KB Output is correct
38 Correct 741 ms 104872 KB Output is correct
39 Correct 693 ms 110764 KB Output is correct
40 Correct 796 ms 109136 KB Output is correct
41 Correct 635 ms 104696 KB Output is correct
42 Correct 578 ms 101148 KB Output is correct
43 Correct 705 ms 109980 KB Output is correct
44 Correct 681 ms 105988 KB Output is correct
45 Correct 584 ms 109004 KB Output is correct
46 Correct 586 ms 109588 KB Output is correct
47 Correct 692 ms 105736 KB Output is correct
48 Correct 1033 ms 105656 KB Output is correct
49 Correct 884 ms 105772 KB Output is correct
50 Correct 698 ms 105528 KB Output is correct
51 Correct 757 ms 108924 KB Output is correct
52 Correct 714 ms 109012 KB Output is correct