제출 #1125369

#제출 시각아이디문제언어결과실행 시간메모리
1125369AgageldiBall Machine (BOI13_ballmachine)C++20
0 / 100
102 ms116304 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; vector <int> v[N]; deque <int> ans; void solve(int x) { set <int> s; for(auto i : v[x]) { s.insert(i); } for(auto i : s) { solve(i); } ans.pb(x); return; } int main () { ios::sync_with_stdio(0);cin.tie(0); cin >> n >> q; for(int i = 1; i <= n; i++) { int x; cin >> x; if(x)v[x].pb(i); else t = i; } solve(t); for(int i = 1; i <= q; i++) { int x; cin >> t >> x; while(t != x) { ans.pop_front(); t++; } cout << ans[0] << '\n'; ans.pop_front(); } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...