#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 |
1 |
Correct |
324 ms |
27808 KB |
Output is correct |
2 |
Correct |
323 ms |
35288 KB |
Output is correct |
3 |
Correct |
292 ms |
33952 KB |
Output is correct |
4 |
Correct |
252 ms |
32668 KB |
Output is correct |
5 |
Correct |
285 ms |
34720 KB |
Output is correct |
6 |
Correct |
274 ms |
32924 KB |
Output is correct |
7 |
Correct |
289 ms |
34972 KB |
Output is correct |
8 |
Correct |
258 ms |
33300 KB |
Output is correct |
9 |
Correct |
266 ms |
32924 KB |
Output is correct |
10 |
Correct |
276 ms |
33556 KB |
Output is correct |
11 |
Correct |
286 ms |
33324 KB |
Output is correct |
12 |
Correct |
227 ms |
32156 KB |
Output is correct |
13 |
Correct |
269 ms |
33176 KB |
Output is correct |
14 |
Correct |
275 ms |
33952 KB |
Output is correct |
15 |
Correct |
273 ms |
34200 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
216 ms |
32616 KB |
Output is correct |
18 |
Correct |
235 ms |
32340 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3063 ms |
30576 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3071 ms |
6356 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
324 ms |
27808 KB |
Output is correct |
2 |
Correct |
323 ms |
35288 KB |
Output is correct |
3 |
Correct |
292 ms |
33952 KB |
Output is correct |
4 |
Correct |
252 ms |
32668 KB |
Output is correct |
5 |
Correct |
285 ms |
34720 KB |
Output is correct |
6 |
Correct |
274 ms |
32924 KB |
Output is correct |
7 |
Correct |
289 ms |
34972 KB |
Output is correct |
8 |
Correct |
258 ms |
33300 KB |
Output is correct |
9 |
Correct |
266 ms |
32924 KB |
Output is correct |
10 |
Correct |
276 ms |
33556 KB |
Output is correct |
11 |
Correct |
286 ms |
33324 KB |
Output is correct |
12 |
Correct |
227 ms |
32156 KB |
Output is correct |
13 |
Correct |
269 ms |
33176 KB |
Output is correct |
14 |
Correct |
275 ms |
33952 KB |
Output is correct |
15 |
Correct |
273 ms |
34200 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
216 ms |
32616 KB |
Output is correct |
18 |
Correct |
235 ms |
32340 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Execution timed out |
3063 ms |
30576 KB |
Time limit exceeded |
22 |
Halted |
0 ms |
0 KB |
- |