제출 #205315

#제출 시각아이디문제언어결과실행 시간메모리
205315medk늑대인간 (IOI18_werewolf)C++14
0 / 100
749 ms30356 KiB
#include "werewolf.h" #include <bits/stdc++.h> #define ll long long #define pb push_back #define x first #define y second using namespace std; vector<vector<int>> g(200001); vector<bool> vis(200001); vector<int> ln,pos(200001); vector<int> check_validity(int n, vector<int> x, vector<int> y, vector<int> s, vector<int> e, vector<int> l, vector<int> r) { int m=x.size(), q=s.size(); for(int i=0;i<m;i++) g[x[i]].pb(y[i]), g[y[i]].pb(x[i]); int leaf; for(int i=0;i<n;i++) if((int)g[i].size()==1) {leaf=i; break;} while((int)ln.size()<n) { pos[leaf]=(int)ln.size(); ln.pb(leaf); vis[leaf]=1; for(int v:g[leaf]) { if(vis[v]) continue; leaf=v; } } vector<pair<int,int>> L,R; for(int i=0;i<q;i++) L.pb({-l[i],i}), R.pb({r[i],i}); sort(L.begin(),L.end()); sort(R.begin(),R.end()); vector<pair<int,int>> lftmost(q); int ptr=n-1; set<pair<int,int>> st; set<pair<int,int>>::iterator it; for(int i=0;i<q;i++) { while(ptr>=-L[i].x) { int ps=pos[ptr]; it=st.upper_bound({ps,ps}); pair<int,int> p={ps,ps}; if(it!=st.end()) if((*it).x==ps+1) p.y=(*it).y, st.erase(it); if((int)st.size()) if(it!=st.begin()) if((*prev(it)).y==ps-1) p.x=(*prev(it)).x, st.erase(prev(it)); st.insert(p); ptr--; } it=prev(st.upper_bound({pos[s[L[i].y]]+1,-1})); lftmost[L[i].y]=*it; } ptr=0; st.clear(); vector<int> ans(q); for(int i=0;i<q;i++) { while(ptr<=R[i].x) { int ps=pos[ptr]; it=st.upper_bound({ps,ps}); pair<int,int> p={ps,ps}; if(it!=st.end()) if((*it).x==ps+1) p.y=(*it).y, st.erase(it); if((int)st.size()) if(it!=st.begin()) if((*prev(it)).y==ps-1) p.x=(*prev(it)).x, st.erase(prev(it)); st.insert(p); ptr++; } it=prev(st.upper_bound({pos[e[R[i].y]]+1,-1})); ans[R[i].y]=!((*it).y<lftmost[R[i].y].x || (*it).x>lftmost[R[i].y].y); } return ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...