Submission #203982

# Submission time Handle Problem Language Result Execution time Memory
203982 2020-02-23T12:11:20 Z LittleFlowers__ Werewolf (IOI18_werewolf) C++14
100 / 100
1580 ms 171236 KB
#include <bits/stdc++.h>
#include "werewolf.h"
using namespace std;
#define in ({int x=0;int c=getchar(),n=0;for(;!isdigit(c);c=getchar()) n=(c=='-');for(;isdigit(c);c=getchar()) x=x*10+c-'0';n?-x:x;})
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int rnd(int l,int r){return l+rng()%(r-l+1);}
#define fasty ios_base::sync_with_stdio(0),cin.tie(0);
#define forinc(a,b,c) for(int a=b,_c=c;a<=_c;++a)
#define fordec(a,b,c) for(int a=b,_c=c;a>=_c;--a)
#define forv(a,b) for(auto&a:b)
#define fi first
#define se second
#define pb push_back
#define ii pair<int,int>
#define mt make_tuple
#define all(a) a.begin(),a.end()
#define reset(f, x) memset(f, x, sizeof(f))
#define bit(x,i) ((x>>(i-1))&1)
#define on(x,i) (x|(1ll<<(i-1)))
#define off(x,i) (x&~(1<<(i-1)))
#define gg exit(0);

const int N=400010;

int n,m,q;

struct pack{
    int u,v,c;
};

struct kruskal{
    int dir, tim, it;
    vector<pack> edg;
    int id[N],st[N],ed[N],val[N],pos[N];
    int f[N][22];
    vector<int> ad[N];

    int root(int x){
        return id[x]==x? x : id[x]=root(id[x]);
    }
    void dfs(int u,int p=-1){
        st[u]=++tim; pos[tim]=u;
        forinc(i,1,20)
            f[u][i]=f[f[u][i-1]][i-1];
        forv(v,ad[u]) if(v!=p){
            f[v][0]=u;
            dfs(v,u);
        }
        ed[u]=tim;
    }
    ii que(int u,int x){
        if((dir && u>x) || (!dir && u<x)) return {n+n,n+n};
        if((dir && val[f[u][0]]>x) || (!dir && val[f[u][0]]<x)) return {st[u],ed[u]};
        u=f[u][0];
        fordec(i,20,0)
            if((dir && val[f[u][i]]<=x) || (!dir && val[f[u][i]]>=x)) u=f[u][i];
        return {st[u],ed[u]};
    }
    void build(int dire){ dir=dire;
        sort(all(edg),[](pack i,pack j){
            return i.c>j.c;
        });
        if(dir) reverse(all(edg));
        int it=n-1;
        forinc(i,1,n+n) id[i]=i;
        forv(i,edg){
            int u=i.u,
                v=i.v,
                c=i.c,
                x=root(u),
                y=root(v);
            if(x==y) continue;
            val[it+1]=c;
            ad[it+1].pb(x);
            ad[it+1].pb(y);
            id[x]=id[y]=++it;
        }

        dfs(f[it][0]=it);
    }
}pf,sf;

int T[N*4];
void upd(int s,int l,int r,int i){
    if(l>i||i>r) return;
    if(l==r){
        T[s]++;
        return;
    }
    int m=(l+r)/2;
    upd(2*s,l,m,i); upd(2*s+1,m+1,r,i);
    T[s]=T[2*s]+T[2*s+1];
}
int que(int s,int l,int r,int u,int v){
    if(l>v||u>r) return 0;
    if(u<=l&&r<=v)
        return T[s];
    int m=(l+r)/2;
    return que(2*s,l,m,u,v)+que(2*s+1,m+1,r,u,v);
}

vector<ii> qry[N];
ii range[N];

vector<int> check_validity(int nw,vector<int> x,vector<int> y,vector<int> st,vector<int> ed,vector<int> lf,vector<int> rt){
    n=nw; m=x.size(), q=st.size();
    vector<int> ans(q);
    forinc(i,0,m-1){
        sf.edg.pb({x[i],y[i],max(x[i],y[i])});
        pf.edg.pb({x[i],y[i],min(x[i],y[i])});
    }
    sf.build(1);
    pf.build(0);
    forinc(i,0,q-1){
        ii u=pf.que(st[i],lf[i]);
        ii v=sf.que(ed[i],rt[i]);
        if(u.fi<n+n && v.fi<n+n){
            range[i]=v;
            qry[u.fi-1].pb({i,-1});
            qry[u.se].pb({i,1});
        }
    }
    forinc(i,1,n+n){
        if(pf.pos[i]<n) upd(1,0,n+n,sf.st[pf.pos[i]]);
        forv(j,qry[i]){
            ans[j.fi]+=j.se * que(1,0,n+n,range[j.fi].fi,range[j.fi].se);
        }
    }
    forv(i,ans) i=i>0;
    return ans;
}
/**
main(){
    #define task "WEREWOLF"
    freopen(task".inp","r",stdin);
    //freopen(task".ans","w",stdout);
    vector<int> x,y,st,ed,lf,rt;
    int n,m,q; cin>>n>>m>>q;
    forinc(i,1,m){
        x.pb(in),y.pb(in);
    }

    forinc(i,1,q){
        st.pb(in), ed.pb(in), lf.pb(in), rt.pb(in);
    }
    forv(i,check_validity(n,x,y,st,ed,lf,rt)) cout<<i<<"\n";
}
*/

# Verdict Execution time Memory Grader output
1 Correct 23 ms 28664 KB Output is correct
2 Correct 24 ms 28664 KB Output is correct
3 Correct 24 ms 28664 KB Output is correct
4 Correct 23 ms 28536 KB Output is correct
5 Correct 24 ms 28664 KB Output is correct
6 Correct 23 ms 28664 KB Output is correct
7 Correct 24 ms 28664 KB Output is correct
8 Correct 23 ms 28664 KB Output is correct
9 Correct 23 ms 28664 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 23 ms 28664 KB Output is correct
2 Correct 24 ms 28664 KB Output is correct
3 Correct 24 ms 28664 KB Output is correct
4 Correct 23 ms 28536 KB Output is correct
5 Correct 24 ms 28664 KB Output is correct
6 Correct 23 ms 28664 KB Output is correct
7 Correct 24 ms 28664 KB Output is correct
8 Correct 23 ms 28664 KB Output is correct
9 Correct 23 ms 28664 KB Output is correct
10 Correct 34 ms 30584 KB Output is correct
11 Correct 34 ms 30456 KB Output is correct
12 Correct 33 ms 30460 KB Output is correct
13 Correct 35 ms 30588 KB Output is correct
14 Correct 36 ms 30712 KB Output is correct
15 Correct 35 ms 30584 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1233 ms 151448 KB Output is correct
2 Correct 1357 ms 162072 KB Output is correct
3 Correct 1168 ms 159128 KB Output is correct
4 Correct 1099 ms 157976 KB Output is correct
5 Correct 1090 ms 158108 KB Output is correct
6 Correct 1253 ms 159256 KB Output is correct
7 Correct 1140 ms 158248 KB Output is correct
8 Correct 1271 ms 161816 KB Output is correct
9 Correct 918 ms 158232 KB Output is correct
10 Correct 791 ms 157552 KB Output is correct
11 Correct 839 ms 157464 KB Output is correct
12 Correct 941 ms 157232 KB Output is correct
13 Correct 1580 ms 163608 KB Output is correct
14 Correct 1567 ms 163480 KB Output is correct
15 Correct 1539 ms 163608 KB Output is correct
16 Correct 1542 ms 163480 KB Output is correct
17 Correct 1106 ms 158360 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 23 ms 28664 KB Output is correct
2 Correct 24 ms 28664 KB Output is correct
3 Correct 24 ms 28664 KB Output is correct
4 Correct 23 ms 28536 KB Output is correct
5 Correct 24 ms 28664 KB Output is correct
6 Correct 23 ms 28664 KB Output is correct
7 Correct 24 ms 28664 KB Output is correct
8 Correct 23 ms 28664 KB Output is correct
9 Correct 23 ms 28664 KB Output is correct
10 Correct 34 ms 30584 KB Output is correct
11 Correct 34 ms 30456 KB Output is correct
12 Correct 33 ms 30460 KB Output is correct
13 Correct 35 ms 30588 KB Output is correct
14 Correct 36 ms 30712 KB Output is correct
15 Correct 35 ms 30584 KB Output is correct
16 Correct 1233 ms 151448 KB Output is correct
17 Correct 1357 ms 162072 KB Output is correct
18 Correct 1168 ms 159128 KB Output is correct
19 Correct 1099 ms 157976 KB Output is correct
20 Correct 1090 ms 158108 KB Output is correct
21 Correct 1253 ms 159256 KB Output is correct
22 Correct 1140 ms 158248 KB Output is correct
23 Correct 1271 ms 161816 KB Output is correct
24 Correct 918 ms 158232 KB Output is correct
25 Correct 791 ms 157552 KB Output is correct
26 Correct 839 ms 157464 KB Output is correct
27 Correct 941 ms 157232 KB Output is correct
28 Correct 1580 ms 163608 KB Output is correct
29 Correct 1567 ms 163480 KB Output is correct
30 Correct 1539 ms 163608 KB Output is correct
31 Correct 1542 ms 163480 KB Output is correct
32 Correct 1106 ms 158360 KB Output is correct
33 Correct 1465 ms 161008 KB Output is correct
34 Correct 580 ms 70148 KB Output is correct
35 Correct 1541 ms 164120 KB Output is correct
36 Correct 1360 ms 160504 KB Output is correct
37 Correct 1522 ms 162968 KB Output is correct
38 Correct 1409 ms 161176 KB Output is correct
39 Correct 1424 ms 167448 KB Output is correct
40 Correct 1463 ms 171236 KB Output is correct
41 Correct 1176 ms 160676 KB Output is correct
42 Correct 939 ms 158232 KB Output is correct
43 Correct 1528 ms 168984 KB Output is correct
44 Correct 1351 ms 161888 KB Output is correct
45 Correct 1115 ms 165928 KB Output is correct
46 Correct 1139 ms 165272 KB Output is correct
47 Correct 1558 ms 163864 KB Output is correct
48 Correct 1537 ms 163752 KB Output is correct
49 Correct 1538 ms 163736 KB Output is correct
50 Correct 1547 ms 163480 KB Output is correct
51 Correct 1349 ms 170428 KB Output is correct
52 Correct 1340 ms 170500 KB Output is correct