Submission #298065

# Submission time Handle Problem Language Result Execution time Memory
298065 2020-09-12T10:51:12 Z muhammad_hokimiyon Werewolf (IOI18_werewolf) C++14
100 / 100
2243 ms 150372 KB
#include "werewolf.h"
#include <bits/stdc++.h>

using namespace std;

#define fi first
#define se second
#define ll long long
#define dl double long

const int maxn = 200200;

int n,m,q;
int tim;
int tin1[maxn];
int tout1[maxn];
int tin2[maxn];
int tout2[maxn];
int p[maxn];
int o1[maxn];
int o2[maxn];
int d1[maxn][25];
int d2[maxn][25];
vector < int > g[maxn];
vector < int > v[maxn],t[4 * maxn];
vector < pair < int , int > > gg[maxn];

void upd( int x , int l , int r , int p , int val )
{
    t[x].push_back(val);
    if( l == r ){
        return;
    }
    int m = (l + r) / 2;
    if( p <= m )upd( x + x , l , m , p , val );
    else upd( x + x + 1 , m + 1 , r , p , val );
}

int get1( int x , int l , int r , int tl , int tr , int tl1 , int tr1 )
{
    if( tl > tr )return 0;
    if( l == tl && r == tr ){
        int y = (int)(lower_bound( t[x].begin() , t[x].end() , tl1 ) - t[x].begin());
        if( y != (int)t[x].size() && t[x][y] <= tr1 )return 1;
        return 0;
    }
    int m = (l + r) / 2;
    return ( get1( x + x , l , m , tl , min( tr , m ) , tl1 , tr1 ) |
               get1( x + x + 1 , m + 1 , r , max( tl , m + 1 ) , tr , tl1 , tr1 ) );
}

int get( int x )
{
    return (p[x] == x ? x : p[x] = get(p[x]));
}

void meg( int x , int y )
{
    int px = get(x);
    int py = get(y);
    if( px == py )return;
    p[px] = py;
    g[py].push_back(px);
    g[px].push_back(py);
}

void dfs( int x , int p )
{
    d1[x][0] = p;
    for( int i = 1; i < 25; i++ ){
        d1[x][i] = d1[d1[x][i - 1]][i - 1];
    }
    tin1[x] = ++tim;
    o1[tim] = x;
    for( auto y : g[x] ){
        if( y == p )continue;
        dfs( y , x );
    }
    tout1[x] = tim;
}

int ff( int x , int y )
{
    for( int i = 24; i >= 0; i-- ){
        if( d2[x][i] <= y ){
            x = d2[x][i];
        }
    }
    return x;
}

int ff1( int x , int y )
{
    for( int i = 24; i >= 0; i-- ){
        if( d1[x][i] >= y ){
            x = d1[x][i];
        }
    }
    return x;
}

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 = (int)X.size();
    q = (int)S.size();
    for( int i = 1; i <= n; i++ ){
        p[i] = i;
    }
    for( int i = 0; i < m; i++ ){
        v[X[i]].push_back(Y[i]);
        v[Y[i]].push_back(X[i]);
    }
    for( int i = 0; i < n; i++ ){
        for( auto x : v[i] ){
            if( x > i )continue;
            meg( x , i );
        }
    }
    dfs( n - 1 , n - 1 );
    for( int i = 0; i <= n; i++ ){
        tin2[i] = tin1[i];
        tout2[i] = tout1[i];
        o2[i] = o1[i];
        g[i].clear();
        p[i] = i;
        for( int j = 0; j < 25; j++ ){
            d2[i][j] = d1[i][j];
        }
    }
    tim = 0;
    for( int i = n - 1; i >= 0; i-- ){
        for( auto x : v[i] ){
            if( x < i )continue;
            meg( x , i );
        }
    }
    dfs( 0 , 0 );
    for( int i = 0; i < q; i++ ){
        gg[R[i]].push_back({L[i] , i});
    }
    for( int i = 0; i < n; i++ ){
        upd( 1 , 0 , n , tin2[i] , tin1[i] );
    }
    for( int i = 0; i < 4 * maxn; i++ ){
        sort( t[i].begin() , t[i].end() );
    }
    vector < int > ans(q , -1);
    for( int i = 0; i < n; i++ ){
        for( auto x : gg[i] ){
            int yy = ff( E[x.se] , i );
            int y = ff1( S[x.se] , x.fi );
            ans[x.se] = get1( 1 , 0 , n , tin2[yy] , tout2[yy] , tin1[y] , tout1[y] );
        }
    }
    return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 30 ms 33280 KB Output is correct
2 Correct 30 ms 33280 KB Output is correct
3 Correct 30 ms 33272 KB Output is correct
4 Correct 29 ms 33280 KB Output is correct
5 Correct 30 ms 33280 KB Output is correct
6 Correct 30 ms 33280 KB Output is correct
7 Correct 30 ms 33280 KB Output is correct
8 Correct 30 ms 33272 KB Output is correct
9 Correct 31 ms 33280 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 30 ms 33280 KB Output is correct
2 Correct 30 ms 33280 KB Output is correct
3 Correct 30 ms 33272 KB Output is correct
4 Correct 29 ms 33280 KB Output is correct
5 Correct 30 ms 33280 KB Output is correct
6 Correct 30 ms 33280 KB Output is correct
7 Correct 30 ms 33280 KB Output is correct
8 Correct 30 ms 33272 KB Output is correct
9 Correct 31 ms 33280 KB Output is correct
10 Correct 45 ms 34808 KB Output is correct
11 Correct 43 ms 34808 KB Output is correct
12 Correct 43 ms 34808 KB Output is correct
13 Correct 42 ms 34936 KB Output is correct
14 Correct 43 ms 34936 KB Output is correct
15 Correct 43 ms 35064 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2125 ms 131432 KB Output is correct
2 Correct 1768 ms 143076 KB Output is correct
3 Correct 1641 ms 140644 KB Output is correct
4 Correct 1714 ms 139968 KB Output is correct
5 Correct 1765 ms 139816 KB Output is correct
6 Correct 1989 ms 139460 KB Output is correct
7 Correct 2000 ms 138612 KB Output is correct
8 Correct 1678 ms 143040 KB Output is correct
9 Correct 1364 ms 141156 KB Output is correct
10 Correct 1231 ms 138208 KB Output is correct
11 Correct 1325 ms 138276 KB Output is correct
12 Correct 1578 ms 139984 KB Output is correct
13 Correct 1638 ms 144352 KB Output is correct
14 Correct 1635 ms 144368 KB Output is correct
15 Correct 1596 ms 144400 KB Output is correct
16 Correct 1462 ms 144356 KB Output is correct
17 Correct 1670 ms 138760 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 30 ms 33280 KB Output is correct
2 Correct 30 ms 33280 KB Output is correct
3 Correct 30 ms 33272 KB Output is correct
4 Correct 29 ms 33280 KB Output is correct
5 Correct 30 ms 33280 KB Output is correct
6 Correct 30 ms 33280 KB Output is correct
7 Correct 30 ms 33280 KB Output is correct
8 Correct 30 ms 33272 KB Output is correct
9 Correct 31 ms 33280 KB Output is correct
10 Correct 45 ms 34808 KB Output is correct
11 Correct 43 ms 34808 KB Output is correct
12 Correct 43 ms 34808 KB Output is correct
13 Correct 42 ms 34936 KB Output is correct
14 Correct 43 ms 34936 KB Output is correct
15 Correct 43 ms 35064 KB Output is correct
16 Correct 2125 ms 131432 KB Output is correct
17 Correct 1768 ms 143076 KB Output is correct
18 Correct 1641 ms 140644 KB Output is correct
19 Correct 1714 ms 139968 KB Output is correct
20 Correct 1765 ms 139816 KB Output is correct
21 Correct 1989 ms 139460 KB Output is correct
22 Correct 2000 ms 138612 KB Output is correct
23 Correct 1678 ms 143040 KB Output is correct
24 Correct 1364 ms 141156 KB Output is correct
25 Correct 1231 ms 138208 KB Output is correct
26 Correct 1325 ms 138276 KB Output is correct
27 Correct 1578 ms 139984 KB Output is correct
28 Correct 1638 ms 144352 KB Output is correct
29 Correct 1635 ms 144368 KB Output is correct
30 Correct 1596 ms 144400 KB Output is correct
31 Correct 1462 ms 144356 KB Output is correct
32 Correct 1670 ms 138760 KB Output is correct
33 Correct 2102 ms 141028 KB Output is correct
34 Correct 508 ms 66808 KB Output is correct
35 Correct 2243 ms 143524 KB Output is correct
36 Correct 2099 ms 140304 KB Output is correct
37 Correct 2137 ms 142948 KB Output is correct
38 Correct 2157 ms 140848 KB Output is correct
39 Correct 1643 ms 149476 KB Output is correct
40 Correct 1896 ms 147924 KB Output is correct
41 Correct 1843 ms 142308 KB Output is correct
42 Correct 1685 ms 140892 KB Output is correct
43 Correct 2097 ms 147300 KB Output is correct
44 Correct 2020 ms 142896 KB Output is correct
45 Correct 1331 ms 150372 KB Output is correct
46 Correct 1380 ms 150244 KB Output is correct
47 Correct 1669 ms 144480 KB Output is correct
48 Correct 1694 ms 144440 KB Output is correct
49 Correct 1662 ms 144580 KB Output is correct
50 Correct 1682 ms 144484 KB Output is correct
51 Correct 1972 ms 147808 KB Output is correct
52 Correct 2055 ms 148096 KB Output is correct