#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, t)].push_back(i);
for (int i=0; i<=n; i++)
{
for (auto x:qrs[i]) res[x]=v[idx[x]];
v=shuffle(v);
//for (int j=1; j<=n; j++) cout<<v[j]<<' ';
//cout<<'\n';
}
for (int i=1; i<=q; i++) cout<<res[i]<<'\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
30 ms |
9052 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3027 ms |
10868 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3030 ms |
9992 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
30 ms |
9052 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |