Submission #1125525

#TimeUsernameProblemLanguageResultExecution timeMemory
1125525AgageldiBall Machine (BOI13_ballmachine)C++20
0 / 100
165 ms119124 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define N 4000005 #define ff first #define ss second #define pb push_back #define sz(s) (int)s.size() #define rep(c, a, b) for(c = a; c <= b; c++) int n, t, q, m, vis[N], par[N], r, dis[N]; vector <int> v[N]; deque <int> ans, jog; void solve(int x) { set <pair<int,int>> s; for(auto i : v[x]) s.insert({dis[i],i}); for(auto i:s) solve(i.ss); ans.pb(x); } void dfs(int x) { for(auto i:v[x]) { dfs(i); dis[x] = min(dis[x],dis[i]); } dis[x] = min(x,dis[x]); } int main () { ios::sync_with_stdio(0);cin.tie(0); cin >> n >> q; for(int i = 0;i<=n;i++) { dis[i] = INT_MAX; } for(int i = 1; i <= n; i++) { int x; cin >> x; if(x) { v[x].pb(i); par[i] = x; } else r = i; } dfs(r); solve(r); par[r] = r; for(int i = 1; i <= q; i++) { int x; cin >> t >> x; if(t == 1) { for(int j = 1; j <= x; j++) { jog.pb(ans[0]); ans.pop_front(); } cout << jog[sz(jog) - 1] << '\n'; continue; } vis[x] = 0; cout << '0' << '\n'; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...