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>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define fst first
#define snd second
#define pb push_back
#define forn(i,a,b) for(int i = a; i < b; i++)
#define ALL(x) x.begin(),x.end()
#define SZ(x) (int)x.size()
#define mset(a,v) memset((a),(v),sizeof(a))
#define FIN ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define dbg(v) cout<<"Line("<<__LINE__<<"): "<<#v<<" = "<<v<<'\n';
#define pi pair<int,int>
#define pll pair<ll,ll>
typedef long long ll;
using namespace std;
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
typedef tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_multiset;
int main(){FIN;
ll n,q; cin>>n>>q;
vector<vector<ll>> states;
states.pb({});
states[0].resize(n);
forn(i,0,n) cin>>states[0][i];
bool repeat=false;
while(!repeat){
queue<ll> A,B;
forn(i,0,n/2) A.push(states[SZ(states)-1][i]);
forn(i,n/2,n) B.push(states[SZ(states)-1][i]);
states.pb({});
states[SZ(states)-1].resize(n);
forn(i,0,n){
if(A.empty()){
states[SZ(states)-1][i]=B.front(); B.pop();
}else if(B.empty()){
states[SZ(states)-1][i]=A.front(); A.pop();
}else if(A.front()<B.front()){
states[SZ(states)-1][i]=A.front(); A.pop();
}else{
states[SZ(states)-1][i]=B.front(); B.pop();
}
}
repeat = true;
ll maxi = 0;
forn(i,0,n/2) maxi = max(maxi,states[SZ(states)-1][i]);
if(states[SZ(states)-1][n/2]<maxi) repeat = false;
}
ll t, i;
while(q--){
cin>>t>>i;
if(SZ(states)<t){
cout<<states[SZ(states)-1][i-1]<<'\n';
}else{
cout<<states[t][i-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... |