Submission #302854

#TimeUsernameProblemLanguageResultExecution timeMemory
302854PajarajaWerewolf (IOI18_werewolf)C++17
0 / 100
1590 ms138676 KiB
#include "werewolf.h" #include <bits/stdc++.h> #define MAXN 200007 using namespace std; int uor[MAXN],seg[20][4*MAXN],dsu[2*MAXN],t,pr[MAXN],l[2*MAXN],r[2*MAXN],sz[2*MAXN],n,pk[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; for(int i=0;i<gg[s].size();i++) dfsg(gg[s][i]); r[s]=br; if(gg[s].size()==0) uor[s]=br++; } void dfssz(int s) { 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) { if(ind==19) return; 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,0,n-1,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,0,n-1,uor[vk[pk[gd[s][i]]][j]],1,1); upd(ind+1,0,n-1,uor[vk[pk[gd[s][i]]][j]],-1,1);} } for(int i=0;i<q[s].size();i++) A[q[s][i]]=(query(ind,0,n-1,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 (stderr)

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:51:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   51 |     for(int i=0;i<gd[s].size();i++) dfssz(gd[s][i]);
      |                 ~^~~~~~~~~~~~~
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++) 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,0,n-1,uor[vk[pk[gd[s][i]]][j]],1,1); upd(ind+1,0,n-1,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,0,n-1,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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...