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;
using ll = long long;
void shuffle(vector<int> &a) {
int n = a.size();
vector<int> b;
int j = n / 2;
for (int i = 0; i < n / 2; i++) {
while (j < n && a[j] < a[i]) {
b.push_back(a[j++]);
}
b.push_back(a[i]);
}
for (int i = j; i < n; i++) {
b.push_back(a[i]);
}
swap(a, b);
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int N, Q;
cin >> N >> Q;
vector<int> A(N);
for (int &x : A) {
cin >> x;
}
vector<vector<int>> T;
set<vector<int>> S;
do {
T.push_back(A);
S.insert(A);
shuffle(A);
} while (!S.count(A));
int M = T.size();
while (Q--) {
int t, i;
cin >> t >> i; i--;
cout << T[t % M][i] << "\n";
}
return 6/22;
}
# | 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... |