Submission #1108658

#TimeUsernameProblemLanguageResultExecution timeMemory
11086580pt1mus23Ball Machine (BOI13_ballmachine)C++14
17.70 / 100
236 ms42952 KiB
#include <bits/stdc++.h> using namespace std; #define int long long int #define ins insert #define pb push_back #define endl '\n' #define putr(x) cout<<x<<endl;return; #define all(x) x.begin(),x.end() const int mod = 1e9 +7, sze = 1e5 +10, inf = LLONG_MAX, LG = 20; vector<int> graph[sze]; int mn[sze]; int depth[sze]; set<pair<int,int>> bos; int lan[sze]; int pp[sze]; int dd[sze]; int up[LG][sze]; void dfs(int node,int par=0){ mn[node]=node; pp[node]=par; up[0][node]=par; for(int i=1;i<LG;i++){ up[i][node]=up[i-1][up[i-1][node]]; } for(auto v:graph[node]){ if(v!=par){ depth[v]=depth[node]+1; dfs(v,node); mn[node]=min(mn[node],mn[v]); // deg++; dd[node]++; } } if(dd[node]==0){ bos.ins({mn[node],node}); } } void rush(){ int n,q; cin>>n>>q; int root=0; for(int i=1;i<=n;i++){ int x;cin>>x; if(x){ graph[i].pb(x); graph[x].pb(i); } else{ root=i; } } dfs(root,root); while(q--){ int op; int node; cin>>op>>node; if(op==1){ int last= 0; while(node--){ if(bos.empty()){ putr("bitdi"); } auto yalvar = *bos.begin(); bos.erase(bos.begin()); lan[yalvar.second]=1; last= yalvar.second; // cout<<last<<" "<<pp[last]<<endl; if(pp[last]){ --dd[pp[last]]; if(dd[pp[last]]==0){ bos.insert({mn[pp[last]],pp[last]}); } } } // cout<<"koala:\n"; cout<<last<<endl; } else{ int emp = node; for(int i= LG-1;i>=0;i--){ if(lan[up[i][emp]]){ emp = up[i][emp]; } } lan[emp]=0; int surus = depth[node] - depth[emp]; cout<</*emp<<" henry "<<*/surus<<endl; if(pp[emp]){ dd[pp[emp]]++; } bos.insert({mn[emp],emp}); } } } signed main(){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int tt = 1; // cin>>tt; while(tt--){ rush(); } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...