This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/******************************************************************************
Online C++ Compiler.
Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.
*******************************************************************************/
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n,q;
cin>>n>>q;
int arr[n];
for(int i=0;i<n;i++){
cin>>arr[i];
}
vector<int>v[n+2];
for(int i=0;i<n;i++){
v[0].push_back(arr[i]);
}
for(int j=1;j<=n;j++){
int prvi=0;
int drugi=n/2;
int t1=0;
while(t1==0){
if(prvi<n/2 and drugi<n){
if(v[j-1][prvi]>v[j-1][drugi]){
v[j].push_back(v[j-1][drugi]);
drugi++;
}else{
v[j].push_back(v[j-1][prvi]);
prvi++;
}
}else{
if(prvi>=n/2){
if(drugi>=n){
t1++;
break;
}else{
v[j].push_back(v[j-1][drugi]);
drugi++;
}
}else{
v[j].push_back(v[j-1][prvi]);
prvi++;
}
}
}
}
while(q--){
int t,i;
cin>>t>>i;
i--;
if(t<=n){
cout<<v[t][i]<<endl;
}else{
cout<<v[n][i]<<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... |