#include <bits/stdc++.h>
using namespace std;
const int nx=2e5+5;
int n, q, idx[nx], res[nx], t;
vector<int> v(nx), qrs[nx];
vector<int> shuffle(vector<int> x)
{
vector<int> l, r, res;
res.push_back(0);
for (int i=n/2; i>=1; i--) l.push_back(v[i]);
for (int i=n; i>n/2; i--) r.push_back(v[i]);
while (l.size()!=0||r.size()!=0)
{
if (r.empty()) res.push_back(l.back()), l.pop_back();
else if (l.empty()) res.push_back(r.back()), r.pop_back();
else if (l.back()<r.back()) res.push_back(l.back()), l.pop_back();
else res.push_back(r.back()), r.pop_back();
}
return res;
}
int main()
{
cin.tie(NULL)->sync_with_stdio(false);
cin>>n>>q;
for (int i=1; i<=n; i++) cin>>v[i];
for (int i=1; i<=q; i++) cin>>t>>idx[i], qrs[min(n+1, t)].push_back(i);
for (int i=0; i<=n+1; i++)
{
for (auto x:qrs[i]) res[x]=v[idx[x]];
v=shuffle(v);
}
for (int i=1; i<=q; i++) cout<<res[i]<<'\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
28 ms |
10836 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3054 ms |
14924 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3005 ms |
11792 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
28 ms |
10836 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |