#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define x first
#define y second
ll dx[]={1, 1, 0,-1,-1, -1, 0, 1};
ll dy[]={0, 1, 1, 1, 0, -1,-1,-1};
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++;
}
if(!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 |
1 |
Incorrect |
319 ms |
35088 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3017 ms |
43680 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3071 ms |
8104 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
319 ms |
35088 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |