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 main(){
ios_base::sync_with_stdio(0); cin.tie(0);
#ifdef LOCAL
freopen("task.inp", "r", stdin);
freopen("task.out", "w", stdout);
#endif // LOCAL
int N, Q;
cin >> N >> Q;
vector<int> p(N);
for(int i = 0; i < N; ++i){
cin >> p[i];
--p[i];
}
vector<vector<int>> results;
results.emplace_back(p);
auto shuffle_cards = [&](vector<int> p) -> vector<int>{
vector<int> q;
int i = 0, j = N / 2;
while(i < N / 2 || j < N){
if(i == N / 2) q.emplace_back(p[j++]);
else if(j == N) q.emplace_back(p[i++]);
else if(p[i] < p[j]) q.emplace_back(p[i++]);
else q.emplace_back(p[j++]);
}
return q;
};
for(int i = 1; i <= N; ++i){
results.emplace_back(shuffle_cards(p));
}
while(Q--){
int t, i;
cin >> t >> i;
--i;
t = min(t, N);
cout << results[t][i] + 1 << '\n';
}
return 0;
}
# | 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... |