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 bulan = 5000;
int n,q;
vector<int> a;
vector<int> qrys[bulan+5];
int rez[1000005],u[1000005];
signed main()
{
ios_base::sync_with_stdio(0);cin.tie(0);
cin>>n>>q;
a.resize(n);
for(int i=0;i<n;i++)
cin>>a[i];
int t;
for(int i=1;i<=q;i++)
{
cin>>t>>u[i];
u[i]--;
t = min(t,bulan);
qrys[t].push_back(i);
rez[i]=-1;
}
for(int pas=0;pas<=bulan+2;pas++)
{
for(auto x:qrys[pas])
rez[x] = a[u[x]];
deque<int> le,ri;
vector<int> newa;
for(int i=0;i<n/2;i++)
le.push_back(a[i]);
for(int i=n/2;i<n;i++)
ri.push_back(a[i]);
for(int i=0;i<n;i++)
{
if(!le.empty() && (ri.empty() || le.front()<ri.front()))
{
newa.push_back(le.front());
le.pop_front();
}
else
{
newa.push_back(ri.front());
ri.pop_front();
}
}
if(a==newa)
{
break;
}
a = newa;
}
for(int i=1;i<=q;i++)
{
if(rez[i]==-1) rez[i] = a[u[i]];
cout<<rez[i]<<"\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... |