# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
340954 | 2020-12-28T18:02:01 Z | a_player | Werewolf (IOI18_werewolf) | C++14 | 169 ms | 21228 KB |
#include "werewolf.h" #include <bits/stdc++.h> #ifdef ALE #include "grader.cpp" #endif #define f first #define s second using namespace std; const int nax=3e3+3; vector<int> grafo[nax]; vector<int> l; bitset<nax> v; int fi[nax]; int ind[nax]; vector<pair<int,int> > o; pair<int,int> ans[nax]; int Ni; void update(int k){ k++; while(k<=Ni){ fi[k]++; k+=k&(-k); } } int query(int k){ if(k==-1)return 0; k++; int sol=0; while(k>0){ sol+=fi[k]; k-=k&(-k); } return sol; } vector<int> check_validity(int N, vector<int> X, vector<int> Y, vector<int> S, vector<int> E, vector<int> L, vector<int> R) { Ni=N; int Q = S.size(); int M=X.size(); vector<int> A(Q); int ini=-1; for(int i=0;i<M;i++){ grafo[X[i]].push_back(Y[i]); grafo[Y[i]].push_back(X[i]); } for(int i=0;i<N;i++) if(grafo[i].size()==1){ ini=i; break; } while(ini!=-1){ v[ini]=1; ind[ini]=l.size(); l.push_back(ini); ini=-1; if(!v[grafo[ini][0]])ini=grafo[ini][0]; else if(grafo[ini].size()>1)ini=grafo[ini][1]; }//------------- for(int i=0;i<Q;i++)o.emplace_back(L[i],i); sort(o.begin(),o.end()); int j=0; for(auto p:o){ while(j<N&&j<p.f){ update(ind[j]); j++; } int l=ind[S[p.s]],r=ind[E[p.s]]; if(l<r){ int x=l-1; for(int b=r-l;b>=1;b/=2) while(x+b<=r&&query(x+b)-query(l-1)==0)x+=b; ans[p.s].f=x+1; } else{ int x=l+1; for(int b=l-r;b>=1;b/=2) while(x-b>=r&&query(l)-query(x-b-1)==0)x-=b; ans[p.s].f=x-1; } } o.clear(); for(int i=0;i<=N;i++)fi[i]=0; for(int i=0;i<Q;i++)o.emplace_back(R[i],i); sort(o.begin(),o.end(),greater<pair<int,int> >()); j=0; for(auto p:o){ while(j<N&&j>p.f){ update(ind[j]); j++; } int l=ind[S[p.s]],r=ind[E[p.s]]; if(l>r){ int x=r-1; for(int b=r-l;b>=1;b/=2) while(x+b<=l&&query(x+b)-query(r-1)==0)x+=b; ans[p.s].s=x+1; } else{ int x=r+1; for(int b=r-l;b>=1;b/=2) while(x-b>=l&&query(r)-query(x-b-1)==0)x-=b; ans[p.s].s=x-1; } } for(int q=0;q<Q;q++){ int s=ind[S[q]],e=ind[E[q]]; if(s<e){ if(ans[q].f<ans[q].s)A[q]=0; else if(ans[q].s+1==ans[q].f)A[q]=0; else A[q]=1; } else{ if(ans[q].f>ans[q].s)A[q]=0; else if(ans[q].s-1==ans[q].f)A[q]=0; else A[q]=1; } } return A; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 364 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 364 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 169 ms | 21228 KB | Execution killed with signal 11 (could be triggered by violating memory limits) |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 364 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |