/* 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 |
1 |
Correct |
202 ms |
18664 KB |
Output is correct |
2 |
Correct |
202 ms |
24544 KB |
Output is correct |
3 |
Correct |
202 ms |
23976 KB |
Output is correct |
4 |
Correct |
181 ms |
22716 KB |
Output is correct |
5 |
Correct |
201 ms |
25936 KB |
Output is correct |
6 |
Correct |
181 ms |
25676 KB |
Output is correct |
7 |
Correct |
197 ms |
26956 KB |
Output is correct |
8 |
Correct |
177 ms |
24524 KB |
Output is correct |
9 |
Correct |
188 ms |
23320 KB |
Output is correct |
10 |
Correct |
183 ms |
23120 KB |
Output is correct |
11 |
Correct |
188 ms |
23660 KB |
Output is correct |
12 |
Correct |
174 ms |
20856 KB |
Output is correct |
13 |
Correct |
181 ms |
22364 KB |
Output is correct |
14 |
Correct |
191 ms |
25036 KB |
Output is correct |
15 |
Correct |
197 ms |
22912 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
172 ms |
21176 KB |
Output is correct |
18 |
Correct |
181 ms |
21008 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
0 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
468 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
468 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
202 ms |
18664 KB |
Output is correct |
2 |
Correct |
202 ms |
24544 KB |
Output is correct |
3 |
Correct |
202 ms |
23976 KB |
Output is correct |
4 |
Correct |
181 ms |
22716 KB |
Output is correct |
5 |
Correct |
201 ms |
25936 KB |
Output is correct |
6 |
Correct |
181 ms |
25676 KB |
Output is correct |
7 |
Correct |
197 ms |
26956 KB |
Output is correct |
8 |
Correct |
177 ms |
24524 KB |
Output is correct |
9 |
Correct |
188 ms |
23320 KB |
Output is correct |
10 |
Correct |
183 ms |
23120 KB |
Output is correct |
11 |
Correct |
188 ms |
23660 KB |
Output is correct |
12 |
Correct |
174 ms |
20856 KB |
Output is correct |
13 |
Correct |
181 ms |
22364 KB |
Output is correct |
14 |
Correct |
191 ms |
25036 KB |
Output is correct |
15 |
Correct |
197 ms |
22912 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
172 ms |
21176 KB |
Output is correct |
18 |
Correct |
181 ms |
21008 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
0 ms |
340 KB |
Output is correct |
21 |
Runtime error |
1 ms |
468 KB |
Execution killed with signal 11 |
22 |
Halted |
0 ms |
0 KB |
- |