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>
#define Loop(x,l,r) for (ll x = (l); x < (r); ++x)
typedef long long ll;
using namespace std;
vector<int> shf(vector<int> vec)
{
int n = vec.size();
vector<int> ans;
int p0 = 0, p1 = n/2;
Loop (_,0,n) {
if (p1 == n || (p0 < n/2 && vec[p0] < vec[p1]))
ans.push_back(vec[p0++]);
else
ans.push_back(vec[p1++]);
}
return ans;
}
vector<vector<int>> vecs;
int main()
{
cin.tie(0) -> sync_with_stdio(false);
int n, q;
cin >> n >> q;
vector<int> vec(n);
for (int &x : vec)
cin >> x;
vecs.push_back(vec);
for (;;) {
vec = shf(vec);
if (vecs.back() == vec)
break;
vecs.push_back(vec);
}
while (q--) {
int t, i;
cin >> t >> i;
--i;
t = min<int>(t, vecs.size()-1);
cout << vecs[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... |