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 MAX = 1e5 + 10 ;
int arr[MAX] ;
int n , q ;
vector<int>v ;
vector<int>ans[MAX] ;
int main()
{
ios_base::sync_with_stdio(0) ;
cin.tie(0) ;
cin>>n>>q ;
v.resize(n) ;
for(auto &x : v)
cin>>x ;
ans[0] = v ;
int last = 0 ;
for(int k = 1 ; ; ++k)
{
vector<int>v2[2] ;
for(int i = n-1 ; i >= 0 ; --i)
v2[(i >= n/2)].push_back(ans[k-1][i]) ;
for(int i = 0 ; i < n ; ++i)
{
bool t = 0 ;
if((!v2[0].size()) || (v2[1].size() && v2[0].back() > v2[1].back()))
t = 1 ;
ans[k].push_back(v2[t].back()) ;
v2[t].pop_back() ;
}
last = k ;
if(ans[k] == ans[k-1])
break ;
}
while(q--)
{
int t , idx ;
cin>>t>>idx ;
t = min(t , last) ;
cout<<ans[t][idx-1]<<"\n" ;
}
return 0 ;
}
# | 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... |