답안 #587135

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
587135 2022-07-01T11:22:12 Z alirezasamimi100 늑대인간 (IOI18_werewolf) C++17
100 / 100
613 ms 105388 KB
#include "werewolf.h"
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
using pii = pair<int, int>;

const int N = 2e5 + 10;

vector<int> rad[2][N],adj[2][N],QL[N],QR[N],QU[2][N];
int st[2][N],fn[2][N],p[2][N],T[2],rv[2][N],f[N];

int gp(int c, int x){
    return p[c][x]!=x?p[c][x]=gp(c,p[c][x]):x;
}

void uni(int c, int v, int u){
    u=gp(c,u);
    if(v==u) return;
    adj[c][v].pb(u);
    p[c][u]=v;
}

void dfs(int c, int v){
    st[c][v]=++T[c];
    rv[c][T[c]]=v;
    for(int u : adj[c][v]) dfs(c,u);
    fn[c][v]=T[c];
}

void upd(int t, int x){
    for(; t<N; t+=t&-t) f[t]+=x;
}

int gt(int t, int x=0){
    for(; t; t-=t&-t) x+=f[t];
    return x;
}

int get(int l, int r){
    return gt(r)-gt(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){
    int M=X.size(), Q=S.size();
    for(int i=0; i<Q; i++){
        QL[L[i]].pb(i);
        QR[R[i]].pb(i);
    }
    vector<int> A(Q);
    for(int i=0; i<M; i++){
        if(X[i]>Y[i]) swap(X[i],Y[i]);
        rad[0][Y[i]].pb(X[i]);
        rad[1][X[i]].pb(Y[i]);
    }
    for(int i=0; i<N; i++) p[0][i]=p[1][i]=i;
    for(int i=0; i<N; i++){
        for(int j : rad[0][i]) uni(0,i,j);
        for(int j : QR[i]){
            E[j]=gp(0,E[j]);
        }
    }
    for(int i=N; i--; ){
        for(int j : rad[1][i]) uni(1,i,j);
        for(int j : QL[i]){
            S[j]=gp(1,S[j]);
        }
    }
    dfs(0,N-1);
    dfs(1,0);
    for(int i=0; i<Q; i++){
        QU[0][st[0][E[i]]-1].pb(i);
        QU[1][fn[0][E[i]]].pb(i);
    }
    for(int i=1; i<=N; i++){
        upd(st[1][rv[0][i]],1);
        for(int j : QU[0][i]) A[j]-=get(st[1][S[j]],fn[1][S[j]]);
        for(int j : QU[1][i]) A[j]+=get(st[1][S[j]],fn[1][S[j]]);
    }
    for(int i=0; i<Q; i++) if(A[i]) A[i]=1;
    return A;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 37972 KB Output is correct
2 Correct 21 ms 37864 KB Output is correct
3 Correct 20 ms 37972 KB Output is correct
4 Correct 18 ms 37916 KB Output is correct
5 Correct 19 ms 37880 KB Output is correct
6 Correct 18 ms 37884 KB Output is correct
7 Correct 18 ms 37920 KB Output is correct
8 Correct 19 ms 37916 KB Output is correct
9 Correct 21 ms 37872 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 37972 KB Output is correct
2 Correct 21 ms 37864 KB Output is correct
3 Correct 20 ms 37972 KB Output is correct
4 Correct 18 ms 37916 KB Output is correct
5 Correct 19 ms 37880 KB Output is correct
6 Correct 18 ms 37884 KB Output is correct
7 Correct 18 ms 37920 KB Output is correct
8 Correct 19 ms 37916 KB Output is correct
9 Correct 21 ms 37872 KB Output is correct
10 Correct 23 ms 38796 KB Output is correct
11 Correct 25 ms 38748 KB Output is correct
12 Correct 23 ms 38604 KB Output is correct
13 Correct 23 ms 38860 KB Output is correct
14 Correct 26 ms 38848 KB Output is correct
15 Correct 29 ms 38832 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 515 ms 91348 KB Output is correct
2 Correct 462 ms 94536 KB Output is correct
3 Correct 512 ms 90908 KB Output is correct
4 Correct 451 ms 89536 KB Output is correct
5 Correct 460 ms 89544 KB Output is correct
6 Correct 521 ms 90484 KB Output is correct
7 Correct 427 ms 87492 KB Output is correct
8 Correct 438 ms 94536 KB Output is correct
9 Correct 453 ms 89876 KB Output is correct
10 Correct 370 ms 87496 KB Output is correct
11 Correct 454 ms 87900 KB Output is correct
12 Correct 421 ms 88572 KB Output is correct
13 Correct 478 ms 104768 KB Output is correct
14 Correct 532 ms 104760 KB Output is correct
15 Correct 527 ms 104768 KB Output is correct
16 Correct 512 ms 104988 KB Output is correct
17 Correct 424 ms 87496 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 37972 KB Output is correct
2 Correct 21 ms 37864 KB Output is correct
3 Correct 20 ms 37972 KB Output is correct
4 Correct 18 ms 37916 KB Output is correct
5 Correct 19 ms 37880 KB Output is correct
6 Correct 18 ms 37884 KB Output is correct
7 Correct 18 ms 37920 KB Output is correct
8 Correct 19 ms 37916 KB Output is correct
9 Correct 21 ms 37872 KB Output is correct
10 Correct 23 ms 38796 KB Output is correct
11 Correct 25 ms 38748 KB Output is correct
12 Correct 23 ms 38604 KB Output is correct
13 Correct 23 ms 38860 KB Output is correct
14 Correct 26 ms 38848 KB Output is correct
15 Correct 29 ms 38832 KB Output is correct
16 Correct 515 ms 91348 KB Output is correct
17 Correct 462 ms 94536 KB Output is correct
18 Correct 512 ms 90908 KB Output is correct
19 Correct 451 ms 89536 KB Output is correct
20 Correct 460 ms 89544 KB Output is correct
21 Correct 521 ms 90484 KB Output is correct
22 Correct 427 ms 87492 KB Output is correct
23 Correct 438 ms 94536 KB Output is correct
24 Correct 453 ms 89876 KB Output is correct
25 Correct 370 ms 87496 KB Output is correct
26 Correct 454 ms 87900 KB Output is correct
27 Correct 421 ms 88572 KB Output is correct
28 Correct 478 ms 104768 KB Output is correct
29 Correct 532 ms 104760 KB Output is correct
30 Correct 527 ms 104768 KB Output is correct
31 Correct 512 ms 104988 KB Output is correct
32 Correct 424 ms 87496 KB Output is correct
33 Correct 541 ms 91436 KB Output is correct
34 Correct 263 ms 72024 KB Output is correct
35 Correct 525 ms 95104 KB Output is correct
36 Correct 613 ms 92216 KB Output is correct
37 Correct 592 ms 94020 KB Output is correct
38 Correct 559 ms 92984 KB Output is correct
39 Correct 461 ms 105160 KB Output is correct
40 Correct 560 ms 99416 KB Output is correct
41 Correct 510 ms 91016 KB Output is correct
42 Correct 441 ms 88564 KB Output is correct
43 Correct 609 ms 100824 KB Output is correct
44 Correct 539 ms 92124 KB Output is correct
45 Correct 503 ms 105388 KB Output is correct
46 Correct 467 ms 104992 KB Output is correct
47 Correct 496 ms 105024 KB Output is correct
48 Correct 487 ms 104772 KB Output is correct
49 Correct 491 ms 104964 KB Output is correct
50 Correct 482 ms 104740 KB Output is correct
51 Correct 548 ms 96100 KB Output is correct
52 Correct 489 ms 96116 KB Output is correct