#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 500;
int n, q, t;
int niz[MAXN];
vector<int> v, novi;
vector<vector<int> > rj;
bool da = false;
int cnt;
void solve () {
for (int i = 0; i < n; i++) v.push_back (niz[i]);
for (int i = 0; i < n; i++) novi.push_back(niz[i]);
while (!da) {
v = novi;
novi.clear ();
int ind1 = 0, ind2 = n / 2;
while (ind1 < n / 2 || ind2 < n) {
if (ind1 == n / 2 || (ind2 < n && v[ind2] < v[ind1])) {
novi.push_back (v[ind2]);
ind2++;
}
else {
novi.push_back (v[ind1]);
ind1++;
}
}
da = true;
for (int i = 0; i < n; i++) {
if (v[i] != novi[i]) da = false;
}
rj.push_back(v);
cnt++;
}
// for (auto it: rj) {
// for (auto itt: it) cout << itt << ' ';
// cout << "\n";
// }
}
int main () {
ios_base::sync_with_stdio(false);
cin.tie (0);
cout.tie (0);
cin >> n >> q;
for (int i = 0; i < n; i++) cin >> niz[i];
solve ();
for (int i = 0; i < q; i++) {
int t, a;
cin >> t >> a;
cout << rj[min (t, cnt - 1)][a - 1] << "\n";
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
180 ms |
15952 KB |
Output is correct |
2 |
Correct |
170 ms |
12628 KB |
Output is correct |
3 |
Correct |
171 ms |
13236 KB |
Output is correct |
4 |
Correct |
155 ms |
10320 KB |
Output is correct |
5 |
Correct |
187 ms |
12112 KB |
Output is correct |
6 |
Correct |
155 ms |
10832 KB |
Output is correct |
7 |
Correct |
174 ms |
12116 KB |
Output is correct |
8 |
Correct |
162 ms |
10780 KB |
Output is correct |
9 |
Correct |
164 ms |
10628 KB |
Output is correct |
10 |
Correct |
156 ms |
10836 KB |
Output is correct |
11 |
Correct |
162 ms |
10916 KB |
Output is correct |
12 |
Correct |
152 ms |
9712 KB |
Output is correct |
13 |
Correct |
183 ms |
10324 KB |
Output is correct |
14 |
Correct |
201 ms |
11344 KB |
Output is correct |
15 |
Correct |
168 ms |
10576 KB |
Output is correct |
16 |
Correct |
0 ms |
344 KB |
Output is correct |
17 |
Correct |
154 ms |
9680 KB |
Output is correct |
18 |
Correct |
166 ms |
9796 KB |
Output is correct |
19 |
Correct |
0 ms |
356 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
648 ms |
524288 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
635 ms |
524288 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
180 ms |
15952 KB |
Output is correct |
2 |
Correct |
170 ms |
12628 KB |
Output is correct |
3 |
Correct |
171 ms |
13236 KB |
Output is correct |
4 |
Correct |
155 ms |
10320 KB |
Output is correct |
5 |
Correct |
187 ms |
12112 KB |
Output is correct |
6 |
Correct |
155 ms |
10832 KB |
Output is correct |
7 |
Correct |
174 ms |
12116 KB |
Output is correct |
8 |
Correct |
162 ms |
10780 KB |
Output is correct |
9 |
Correct |
164 ms |
10628 KB |
Output is correct |
10 |
Correct |
156 ms |
10836 KB |
Output is correct |
11 |
Correct |
162 ms |
10916 KB |
Output is correct |
12 |
Correct |
152 ms |
9712 KB |
Output is correct |
13 |
Correct |
183 ms |
10324 KB |
Output is correct |
14 |
Correct |
201 ms |
11344 KB |
Output is correct |
15 |
Correct |
168 ms |
10576 KB |
Output is correct |
16 |
Correct |
0 ms |
344 KB |
Output is correct |
17 |
Correct |
154 ms |
9680 KB |
Output is correct |
18 |
Correct |
166 ms |
9796 KB |
Output is correct |
19 |
Correct |
0 ms |
356 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Runtime error |
648 ms |
524288 KB |
Execution killed with signal 9 |
22 |
Halted |
0 ms |
0 KB |
- |