This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "bits/stdc++.h"
using namespace std;
#ifdef LOCAL
#include "debug.cpp"
#else
#define debug(...)
#endif
signed main() {
ios_base::sync_with_stdio(false);cin.tie(0);
int n,q;
cin>>n>>q;
deque<int> v;
vector<vector<int>> ver;
ver.push_back({});
for(int i = 0;i<n;i++){
int x;cin>>x;
ver[0].push_back(x);
v.push_back(x);
}
while(1){
deque<int> p1,p2,all;
int x = n/2;
while(x--){
p1.push_back(v[0]);v.pop_front();
}
x = n/2;
while(x--){
p2.push_back(v[0]);v.pop_front();
}
while(p1.size()&&p2.size()){
if(p1[0]<p2[0]){
all.push_back(p1[0]);p1.pop_front();
}else{
all.push_back(p2[0]);p2.pop_front();
}
}
while(p1.size()){
all.push_back(p1[0]);p1.pop_front();
}while(p2.size()){
all.push_back(p2[0]);p2.pop_front();
}
swap(v,all);bool ss = 0;
for(int i = 0;i<n;i++){
if(ver.back()[i]!=v[i]){
ss = 1;
}
}
if(!ss)break;
ver.push_back({});
for(int i = 0;i<n;i++){
ver.back().push_back(v[i]);
}
}
while(q--){
int a,b;cin>>a>>b;
a = min(a,(int)ver.size()-1);
cout<<ver[a][b-1]<<endl;
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |