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;
typedef long long ll;
#define x first
#define y second
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
ll n,t;
cin>>n>>t;
vector<ll> cad(n);
for(int i=0; i<n; i++)
cin>>cad[i];
vector<ll> fin=cad; sort(fin.begin(),fin.end());
priority_queue<pair<ll,ll>> q;
vector<ll> query(t,0);
for(int i=0; i<t; i++)
{
ll a,b;
cin>>a>>b;
query[i]=b;
q.push({-a,i});
}
ll cnt=0;
while(fin!=cad)
{
while(!q.empty()&&-cnt==q.top().first)
{
query[q.top().second]=cad[query[q.top().second]-1];
q.pop();
}
if(q.empty()) break;
fin=cad;
vector<ll> temp;
ll i=0;
ll d=n/2;
while(i!=n/2||d!=n)
{
if(i==n/2)
{
while(d<n)
{
temp.push_back(cad[d]);
d++;
}
}
else if(d==n)
{
while(i<n/2)
{
temp.push_back(cad[i]);
i++;
}
}
else if(cad[i]<cad[d])
temp.push_back(cad[i++]);
else temp.push_back(cad[d++]);
}
cad=temp;
cnt++;
}
while(!q.empty())
{
query[q.top().second]=cad[query[q.top().second]-1];
q.pop();
}
for(auto i:query)
cout<<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... |