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;
const int maxn=1000+10;
int n,q;
int all[maxn][maxn];
void solve(int ind){
int i=1,j=n/2+1;
int z=1;
while(i<=(n/2)&&j<=n){
if(all[ind-1][i]<all[ind-1][j]){
all[ind][z]=all[ind-1][i];
z++;
i++;
}
else{
all[ind][z]=all[ind-1][j];
j++;
z++;
}
}
while(i<=(n/2)){
all[ind][z]=all[ind-1][i];
i++;
z++;
}
while(j<=n){
all[ind][z]=all[ind-1][j];
j++;
z++;
}
return ;
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>n>>q;
for(int i=1;i<=n;i++){
cin>>all[0][i];
}
for(int j=1;j<=n/2+2;j++){
solve(j);
}
/*for(int i=0;i<=n;i++){
for(int j=1;j<=n;j++){
cout<<all[i][j]<<" ";
}
cout<<"\n";
}
cout<<"\n";*/
for(int i=0;i<q;i++){
int u,v;
cin>>u>>v;
u=min(u,n/2+2);
cout<<all[u][v]<<"\n";
}
}
# | 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... |