Submission #983430

#TimeUsernameProblemLanguageResultExecution timeMemory
983430alexddAbracadabra (CEOI22_abracadabra)C++17
10 / 100
3024 ms30152 KiB
#include<bits/stdc++.h> using namespace std; const int bulan = 5000; int n,q; vector<int> a; vector<int> qrys[bulan+5]; int rez[1000005],u[1000005]; signed main() { ios_base::sync_with_stdio(0);cin.tie(0); cin>>n>>q; a.resize(n); for(int i=0;i<n;i++) cin>>a[i]; int t; for(int i=1;i<=q;i++) { cin>>t>>u[i]; u[i]--; t = min(t,bulan); qrys[t].push_back(i); rez[i]=-1; } for(int pas=0;pas<=bulan+2;pas++) { for(auto x:qrys[pas]) rez[x] = a[u[x]]; deque<int> le,ri; vector<int> newa; for(int i=0;i<n/2;i++) le.push_back(a[i]); for(int i=n/2;i<n;i++) ri.push_back(a[i]); for(int i=0;i<n;i++) { if(!le.empty() && (ri.empty() || le.front()<ri.front())) { newa.push_back(le.front()); le.pop_front(); } else { newa.push_back(ri.front()); ri.pop_front(); } } if(a==newa) { break; } a = newa; } for(int i=1;i<=q;i++) { if(rez[i]==-1) rez[i] = a[u[i]]; cout<<rez[i]<<"\n"; } 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...