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;
#define pb push_back
const int N=1e4;
int n,q;
vector<vector<int>>v;
map<int,vector<int>>mp;
vector<int>ans;
signed main(){
cin>>n>>q;
vector<int>vc;
for(int i=1;i<=n;i++){
int a;
cin>>a;
vc.pb(a);
}
mp[0]=vc;
int y=0;
for(int l=1;l<=n;l++){
vc=mp[l-1];
vector<int>vec;
int i = 0, j = n/2;
while(i<n/2 and j<n){
if(vc[i]<vc[j]){
vec.pb(vc[i++]);
}
else{
vec.pb(vc[j++]);
}
}
while(i<n/2){
vec.pb(vc[i++]);
}
while(j<n)vec.pb(vc[j++]);
mp[l]=vec;
y=l;
if(mp[l]==mp[l-1])break;
}
while(q--){
int t,idx;
cin>>t>>idx;
idx--;
if(t>y)t=y;
ans.pb(mp[t][idx]);
}
for(auto a:ans)cout<<a<<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... |