//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("Ofast,unroll-loops,fast-math,O3")
#include<bits/stdc++.h>
using namespace std;
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define sz(a) (int)a.size()
#define pf push_front
#define pb push_back
#define vt vector
#define s second
#define f first
#define nl '\n'
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
vt<pii> rid = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};
vt<pii> dir = {{-1, -1}, {-1, 1}, {1, -1}, {1, 1}};
const int N = 5e5, mod = 1e9 + 7;
const ll inf = 1e18;
double eps = 1e-15;
bool flg = 0;
int p[N], n, q;
void slv() {
cin >> n >> q;
for (int i = 1; i <= n; i++) cin >> p[i];
int ans[n + 1][n + 1];
for (int i = 1; i <= n; i++) ans[0][i] = p[i];
for (int t = 1; t <= n; t++) {
vt<int> s, h;
for (int i = 1; i <= n / 2; i++) s.pb(ans[t - 1][i]);
for (int i = n / 2 + 1; i <= n; i++) h.pb(ans[t - 1][i]);
vt<int> z;
int i = 0, j = 0;
while (i < sz(s) || j < sz(h)) {
if (j == sz(h) || (i < sz(s) && s[i] < h[j])) z.pb(s[i++]);
else z.pb(h[j++]);
}
for (i = 1; i <= n; i++) ans[t][i] = z[i - 1];
}
while (q--) {
int t, k;
cin >> t >> k;
t = min(t, n);
cout << ans[t][k] << nl;
}
}
main() {
//freopen("shops.in", "r", stdin);
//freopen("shops.out", "w", stdout);
ios_base::sync_with_stdio(0);
cin.tie(0);
int tp = 1;
if (flg) cin >> tp;
while (tp--) {
slv();
}
}
Compilation message
Main.cpp:62:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
62 | main() {
| ^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
291 ms |
8072 KB |
Output is correct |
2 |
Correct |
224 ms |
8056 KB |
Output is correct |
3 |
Correct |
267 ms |
7804 KB |
Output is correct |
4 |
Correct |
190 ms |
7772 KB |
Output is correct |
5 |
Correct |
221 ms |
8012 KB |
Output is correct |
6 |
Correct |
209 ms |
7620 KB |
Output is correct |
7 |
Correct |
239 ms |
8048 KB |
Output is correct |
8 |
Correct |
201 ms |
7592 KB |
Output is correct |
9 |
Correct |
200 ms |
7904 KB |
Output is correct |
10 |
Correct |
193 ms |
7596 KB |
Output is correct |
11 |
Correct |
217 ms |
7948 KB |
Output is correct |
12 |
Correct |
190 ms |
7572 KB |
Output is correct |
13 |
Correct |
228 ms |
7692 KB |
Output is correct |
14 |
Correct |
276 ms |
7936 KB |
Output is correct |
15 |
Correct |
201 ms |
7952 KB |
Output is correct |
16 |
Correct |
10 ms |
4204 KB |
Output is correct |
17 |
Correct |
221 ms |
7792 KB |
Output is correct |
18 |
Correct |
219 ms |
7628 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
235 ms |
524288 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
212 ms |
524288 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
291 ms |
8072 KB |
Output is correct |
2 |
Correct |
224 ms |
8056 KB |
Output is correct |
3 |
Correct |
267 ms |
7804 KB |
Output is correct |
4 |
Correct |
190 ms |
7772 KB |
Output is correct |
5 |
Correct |
221 ms |
8012 KB |
Output is correct |
6 |
Correct |
209 ms |
7620 KB |
Output is correct |
7 |
Correct |
239 ms |
8048 KB |
Output is correct |
8 |
Correct |
201 ms |
7592 KB |
Output is correct |
9 |
Correct |
200 ms |
7904 KB |
Output is correct |
10 |
Correct |
193 ms |
7596 KB |
Output is correct |
11 |
Correct |
217 ms |
7948 KB |
Output is correct |
12 |
Correct |
190 ms |
7572 KB |
Output is correct |
13 |
Correct |
228 ms |
7692 KB |
Output is correct |
14 |
Correct |
276 ms |
7936 KB |
Output is correct |
15 |
Correct |
201 ms |
7952 KB |
Output is correct |
16 |
Correct |
10 ms |
4204 KB |
Output is correct |
17 |
Correct |
221 ms |
7792 KB |
Output is correct |
18 |
Correct |
219 ms |
7628 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Runtime error |
235 ms |
524288 KB |
Execution killed with signal 9 |
22 |
Halted |
0 ms |
0 KB |
- |