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;
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 |
---|
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... |