Submission #828538

#TimeUsernameProblemLanguageResultExecution timeMemory
828538vnm06Werewolf (IOI18_werewolf)C++14
0 / 100
376 ms56348 KiB
#include<bits/stdc++.h> #include "werewolf.h" using namespace std; int n, m; int pos[200005]; vector<int> gr[200005]; void dfs(int v) { for(int i=0; i<gr[v].size(); i++) { int nv=gr[v][i]; if(pos[nv]) continue; pos[nv]=pos[v]+1; v=nv; dfs(v); } } vector<int> zL[200005]; vector<int> zR[200005]; vector<int> res; int posL[200005], posR[200005]; int treeL[800005], treeR[800005]; void update_L(int v, int le, int ri, int pos) { if(le>pos || ri<pos) return; if(le==ri) { treeL[v]=pos; return; } int mid=(le+ri)/2; update_L(2*v, le, mid, pos); update_L(2*v+1, mid+1, ri, pos); treeL[v]=min(treeL[2*v], treeL[2*v+1]); } void update_R(int v, int le, int ri, int pos) { if(le>pos || ri<pos) return; if(le==ri) { treeR[v]=pos; return; } int mid=(le+ri)/2; update_R(2*v, le, mid, pos); update_R(2*v+1, mid+1, ri, pos); treeR[v]=max(treeR[2*v], treeR[2*v+1]); } int query_L(int v, int le, int ri, int be, int en) { if(ri<be || le>en) return en+1; if(be<=le && ri<=en) return treeL[v]; int mid=(le+ri)/2; return min(query_L(2*v, le, mid, be, en), query_L(2*v+1, mid+1, ri, be, en)); } int query_R(int v, int le, int ri, int be, int en) { if(ri<be || le>en) return be-1; if(be<=le && ri<=en) return treeR[v]; int mid=(le+ri)/2; return max(query_R(2*v, le, mid, be, en), query_R(2*v+1, mid+1, ri, be, en)); } 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) { n=N; m=X.size(); for(int i=0; i<m; i++) { gr[X[i]].push_back(Y[i]); gr[Y[i]].push_back(X[i]); } for(int i=0; i<n; i++) { if(gr[i].size()==1) { pos[i]=1; dfs(i); break; } } int q=S.size(); for(int i=0; i<q; i++) { zL[L[i]].push_back(i); zR[R[i]].push_back(i); } for(int i=0; i<=800000; i++) { treeL[i]=n+2; treeR[i]=-2; } for(int i=0; i<=n-1; i++) { int brid=zL[i].size(); for(int j=0; j<brid; j++) { int id=zL[i][j]; int ts=S[id], te=E[id]; posL[id]=query_L(1, 1, n, ts, te); } update_L(1, 1, n, pos[i]); } for(int i=n-1; i>=0; i--) { int brid=zR[i].size(); for(int j=0; j<brid; j++) { int id=zR[i][j]; int ts=S[id], te=E[id]; posR[id]=query_R(1, 1, n, ts, te); } update_R(1, 1, n, pos[i]); } for(int i=0; i<q; i++) { if(posL[i]>posR[i]+1) res.push_back(1); else res.push_back(0); } return res; }

Compilation message (stderr)

werewolf.cpp: In function 'void dfs(int)':
werewolf.cpp:12:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   12 |     for(int i=0; i<gr[v].size(); i++)
      |                  ~^~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...