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;
int n;
vector<vector<int>> all;
vector<int> shuffle(vector<int> v)
{
deque<int> dq[2];
for(int i = 0 ; i < n ; i++)
{
dq[i / (n/2)].push_back(v[i]);
}
vector<int> ret;
while(!dq[0].empty() && !dq[1].empty())
{
ret.push_back(min(dq[0].front() , dq[1].front()));
if(dq[0].front() < dq[1].front())
{
dq[0].pop_front();
}
else
{
dq[1].pop_front();
}
}
for(int i = 0 ; i < 2 ; i++)
{
for(auto x : dq[i])
ret.push_back(x);
}
return ret;
}
int main() {
int q;
cin>>n>>q;
all.assign(n , {});
vector<int> a(n);
for(int i = 0 ; i < n ; i++)
cin>>a[i];
all[0] = a;
for(int i =1 ; i <= n - 1; i++)
all[i] = shuffle(all[i - 1]);
while(q--)
{
int t , i;
cin>>t>>i;
i-- ;
t = min(t , n - 1);
cout<<all[t][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... |