Submission #303820

# Submission time Handle Problem Language Result Execution time Memory
303820 2020-09-20T16:28:42 Z Pajaraja Werewolf (IOI18_werewolf) C++17
100 / 100
1551 ms 144780 KB
#include "werewolf.h"
#include <bits/stdc++.h>
#define MAXN 200007
using namespace std;
int uor[MAXN],seg[25][4*MAXN],dsu[2*MAXN],t,pr[MAXN],l[2*MAXN],r[2*MAXN],sz[2*MAXN],n,pk[2*MAXN],br;
vector<int> g[MAXN],gg[2*MAXN],gd[2*MAXN],s[MAXN],e[MAXN],q[3*MAXN],A,vk[2*MAXN];
void upd(int k,int l,int r,int v,int val,int ind)
{
    if(l==r) {seg[k][ind]+=val; return;}
    int s=(l+r)/2;
    if(v<=s) upd(k,l,s,v,val,2*ind);
    else upd(k,s+1,r,v,val,2*ind+1);
    seg[k][ind]+=val;
}
int query(int k,int l,int r,int lt,int rt,int ind)
{
    if(l>=lt && r<=rt) return seg[k][ind];
    if(r<lt || l>rt) return 0;
    int s=(l+r)/2;
    return query(k,l,s,lt,rt,2*ind)+query(k,s+1,r,lt,rt,2*ind+1);
}
int root(int u)
{
    while(dsu[u]!=u)
    {
        dsu[u]=dsu[dsu[u]];
        u=dsu[u];
    }
    return u;
}
void connect(int u,int v,int trg)
{
    int a=root(u),b=root(v);
    if(a==b) return;
    dsu[a]=dsu[b]=dsu[t]=t;
    if(trg==1) gd[t].push_back(a);
    else gg[t].push_back(a);
    if(trg==1) gd[t].push_back(b);
    else gg[t].push_back(b);
    t++;
}
void dfsg(int s)
{
    l[s]=br+1;
    for(int i=0;i<gg[s].size();i++) dfsg(gg[s][i]);
    if(gg[s].size()==0) uor[s]=++br;
    r[s]=br;
}
void dfssz(int s)
{
    sz[s]=0;
    for(int i=0;i<gd[s].size();i++) dfssz(gd[s][i]);
    for(int i=0;i<gd[s].size();i++) sz[s]+=sz[gd[s][i]];
    if(gd[s].size()==0) sz[s]=1;
}
bool cmp(int a,int b) {return sz[a]>sz[b];}
void dfsd(int s,int ind)
{
    sort(gd[s].begin(),gd[s].end(),cmp);
    if(gd[s].size()!=0) {dfsd(gd[s][0],ind); pk[s]=pk[gd[s][0]];}
    else {pk[s]=s; vk[s].push_back(s); upd(ind,1,n,uor[s],1,1);}
    for(int i=1;i<gd[s].size();i++)
    {
        dfsd(gd[s][i],ind+1);
        for(int j=0;j<vk[pk[gd[s][i]]].size();j++) {vk[pk[s]].push_back(vk[pk[gd[s][i]]][j]); upd(ind,1,n,uor[vk[pk[gd[s][i]]][j]],1,1); upd(ind+1,1,n,uor[vk[pk[gd[s][i]]][j]],-1,1);}
    }
    for(int i=0;i<q[s].size();i++) A[q[s][i]]=(query(ind,1,n,l[pr[q[s][i]]],r[pr[q[s][i]]],1)>0)?1:0;
}
std::vector<int> check_validity(int N, std::vector<int> X, std::vector<int> Y,
                                std::vector<int> S, std::vector<int> E,
                                std::vector<int> L, std::vector<int> R) {
    int Q = S.size(); n=N;
    for(int i=0;i<Q;i++) A.push_back(0);
    for(int i=0;i<X.size();i++) g[X[i]].push_back(Y[i]);
    for(int i=0;i<X.size();i++) g[Y[i]].push_back(X[i]);
    for(int i=0;i<Q;i++) e[R[i]].push_back(i);
    for(int i=0;i<Q;i++) s[L[i]].push_back(i);
    for(int i=0;i<N;i++) dsu[i]=i;
    t=N;
    for(int i=0;i<N;i++)
    {
        for(int j=0;j<g[i].size();j++) if(i>g[i][j]) connect(i,g[i][j],1);
        for(int j=0;j<e[i].size();j++) q[root(E[e[i][j]])].push_back(e[i][j]);
    }
    for(int i=0;i<N;i++) dsu[i]=i;
    t=N;
    for(int i=N-1;i>=0;i--)
    {
        for(int j=0;j<g[i].size();j++) if(i<g[i][j]) connect(i,g[i][j],2);
        for(int j=0;j<s[i].size();j++) pr[s[i][j]]=root(S[s[i][j]]);
    }
    dfsg(2*N-2);
    dfssz(2*N-2);
    dfsd(2*N-2,0);
    return A;
}

Compilation message

werewolf.cpp: In function 'void dfsg(int)':
werewolf.cpp:45:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   45 |     for(int i=0;i<gg[s].size();i++) dfsg(gg[s][i]);
      |                 ~^~~~~~~~~~~~~
werewolf.cpp: In function 'void dfssz(int)':
werewolf.cpp:52:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   52 |     for(int i=0;i<gd[s].size();i++) dfssz(gd[s][i]);
      |                 ~^~~~~~~~~~~~~
werewolf.cpp:53:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   53 |     for(int i=0;i<gd[s].size();i++) sz[s]+=sz[gd[s][i]];
      |                 ~^~~~~~~~~~~~~
werewolf.cpp: In function 'void dfsd(int, int)':
werewolf.cpp:62:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   62 |     for(int i=1;i<gd[s].size();i++)
      |                 ~^~~~~~~~~~~~~
werewolf.cpp:65:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   65 |         for(int j=0;j<vk[pk[gd[s][i]]].size();j++) {vk[pk[s]].push_back(vk[pk[gd[s][i]]][j]); upd(ind,1,n,uor[vk[pk[gd[s][i]]][j]],1,1); upd(ind+1,1,n,uor[vk[pk[gd[s][i]]][j]],-1,1);}
      |                     ~^~~~~~~~~~~~~~~~~~~~~~~~
werewolf.cpp:67:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   67 |     for(int i=0;i<q[s].size();i++) A[q[s][i]]=(query(ind,1,n,l[pr[q[s][i]]],r[pr[q[s][i]]],1)>0)?1:0;
      |                 ~^~~~~~~~~~~~
werewolf.cpp: In function 'std::vector<int> check_validity(int, std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
werewolf.cpp:74:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   74 |     for(int i=0;i<X.size();i++) g[X[i]].push_back(Y[i]);
      |                 ~^~~~~~~~~
werewolf.cpp:75:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   75 |     for(int i=0;i<X.size();i++) g[Y[i]].push_back(X[i]);
      |                 ~^~~~~~~~~
werewolf.cpp:82:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   82 |         for(int j=0;j<g[i].size();j++) if(i>g[i][j]) connect(i,g[i][j],1);
      |                     ~^~~~~~~~~~~~
werewolf.cpp:83:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   83 |         for(int j=0;j<e[i].size();j++) q[root(E[e[i][j]])].push_back(e[i][j]);
      |                     ~^~~~~~~~~~~~
werewolf.cpp:89:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   89 |         for(int j=0;j<g[i].size();j++) if(i<g[i][j]) connect(i,g[i][j],2);
      |                     ~^~~~~~~~~~~~
werewolf.cpp:90:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   90 |         for(int j=0;j<s[i].size();j++) pr[s[i][j]]=root(S[s[i][j]]);
      |                     ~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 36 ms 56824 KB Output is correct
2 Correct 35 ms 56824 KB Output is correct
3 Correct 35 ms 56704 KB Output is correct
4 Correct 35 ms 56704 KB Output is correct
5 Correct 36 ms 56832 KB Output is correct
6 Correct 35 ms 56824 KB Output is correct
7 Correct 36 ms 56824 KB Output is correct
8 Correct 35 ms 56824 KB Output is correct
9 Correct 35 ms 56696 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 36 ms 56824 KB Output is correct
2 Correct 35 ms 56824 KB Output is correct
3 Correct 35 ms 56704 KB Output is correct
4 Correct 35 ms 56704 KB Output is correct
5 Correct 36 ms 56832 KB Output is correct
6 Correct 35 ms 56824 KB Output is correct
7 Correct 36 ms 56824 KB Output is correct
8 Correct 35 ms 56824 KB Output is correct
9 Correct 35 ms 56696 KB Output is correct
10 Correct 45 ms 58108 KB Output is correct
11 Correct 47 ms 57976 KB Output is correct
12 Correct 46 ms 57976 KB Output is correct
13 Correct 44 ms 57976 KB Output is correct
14 Correct 44 ms 58112 KB Output is correct
15 Correct 46 ms 58104 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1551 ms 138432 KB Output is correct
2 Correct 900 ms 135788 KB Output is correct
3 Correct 949 ms 133484 KB Output is correct
4 Correct 1037 ms 135472 KB Output is correct
5 Correct 1069 ms 136172 KB Output is correct
6 Correct 1244 ms 138732 KB Output is correct
7 Correct 1432 ms 144780 KB Output is correct
8 Correct 874 ms 135788 KB Output is correct
9 Correct 872 ms 132460 KB Output is correct
10 Correct 937 ms 133612 KB Output is correct
11 Correct 994 ms 134508 KB Output is correct
12 Correct 1118 ms 137836 KB Output is correct
13 Correct 859 ms 134448 KB Output is correct
14 Correct 882 ms 134380 KB Output is correct
15 Correct 890 ms 134636 KB Output is correct
16 Correct 872 ms 134764 KB Output is correct
17 Correct 1393 ms 144620 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 36 ms 56824 KB Output is correct
2 Correct 35 ms 56824 KB Output is correct
3 Correct 35 ms 56704 KB Output is correct
4 Correct 35 ms 56704 KB Output is correct
5 Correct 36 ms 56832 KB Output is correct
6 Correct 35 ms 56824 KB Output is correct
7 Correct 36 ms 56824 KB Output is correct
8 Correct 35 ms 56824 KB Output is correct
9 Correct 35 ms 56696 KB Output is correct
10 Correct 45 ms 58108 KB Output is correct
11 Correct 47 ms 57976 KB Output is correct
12 Correct 46 ms 57976 KB Output is correct
13 Correct 44 ms 57976 KB Output is correct
14 Correct 44 ms 58112 KB Output is correct
15 Correct 46 ms 58104 KB Output is correct
16 Correct 1551 ms 138432 KB Output is correct
17 Correct 900 ms 135788 KB Output is correct
18 Correct 949 ms 133484 KB Output is correct
19 Correct 1037 ms 135472 KB Output is correct
20 Correct 1069 ms 136172 KB Output is correct
21 Correct 1244 ms 138732 KB Output is correct
22 Correct 1432 ms 144780 KB Output is correct
23 Correct 874 ms 135788 KB Output is correct
24 Correct 872 ms 132460 KB Output is correct
25 Correct 937 ms 133612 KB Output is correct
26 Correct 994 ms 134508 KB Output is correct
27 Correct 1118 ms 137836 KB Output is correct
28 Correct 859 ms 134448 KB Output is correct
29 Correct 882 ms 134380 KB Output is correct
30 Correct 890 ms 134636 KB Output is correct
31 Correct 872 ms 134764 KB Output is correct
32 Correct 1393 ms 144620 KB Output is correct
33 Correct 1327 ms 140268 KB Output is correct
34 Correct 396 ms 92652 KB Output is correct
35 Correct 1210 ms 141688 KB Output is correct
36 Correct 1325 ms 140412 KB Output is correct
37 Correct 1208 ms 140652 KB Output is correct
38 Correct 1296 ms 139756 KB Output is correct
39 Correct 918 ms 140780 KB Output is correct
40 Correct 1154 ms 140524 KB Output is correct
41 Correct 1127 ms 138480 KB Output is correct
42 Correct 1153 ms 137260 KB Output is correct
43 Correct 1197 ms 144492 KB Output is correct
44 Correct 1157 ms 139812 KB Output is correct
45 Correct 847 ms 140652 KB Output is correct
46 Correct 885 ms 140524 KB Output is correct
47 Correct 914 ms 134764 KB Output is correct
48 Correct 924 ms 134636 KB Output is correct
49 Correct 894 ms 134892 KB Output is correct
50 Correct 873 ms 134764 KB Output is correct
51 Correct 1120 ms 139116 KB Output is correct
52 Correct 1138 ms 138860 KB Output is correct