This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/* In the name of God, aka Allah */
// Believe me - Takeshi Abo
#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define endl '\n'
#define mk make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int N = 1050, M = 1e6 + 50;
int n, q, a[N], b[N], out[M];
vector<pii> vc[N];
void solve() {
cin >> n >> q;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
for (int i = 1; i <= q; i++) {
int t, k;
cin >> t >> k;
t = min(t, n);
vc[t].push_back({k, i});
}
for (pii x:vc[0]) out[x.S] = a[x.F];
for (int tt = 1; tt <= n; tt++) {
int pt = 1, p1 = 1, p2 = n/2+1;
while (p1 <= n/2 && p2 <= n) {
if (a[p1] < a[p2]) b[pt++] = a[p1++];
else b[pt++] = a[p2++];
}
while (p1 <= n/2) {
b[pt++] = a[p1++];
}
while (p2 <= n) {
b[pt++] = a[p2++];
}
for (int i = 1; i <= n; i++) {
a[i] = b[i];
}
for (pii x:vc[tt]) {
out[x.S] = a[x.F];
}
}
for (int i = 1; i <= q; i++ ){
cout << out[i] << endl;
}
}
int main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
solve();
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... |