//#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() {
| ^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
252 ms |
8456 KB |
Output is correct |
2 |
Correct |
210 ms |
8380 KB |
Output is correct |
3 |
Correct |
206 ms |
8140 KB |
Output is correct |
4 |
Correct |
186 ms |
8164 KB |
Output is correct |
5 |
Correct |
211 ms |
8380 KB |
Output is correct |
6 |
Correct |
184 ms |
7876 KB |
Output is correct |
7 |
Correct |
226 ms |
8308 KB |
Output is correct |
8 |
Correct |
182 ms |
7900 KB |
Output is correct |
9 |
Correct |
197 ms |
8136 KB |
Output is correct |
10 |
Correct |
187 ms |
8004 KB |
Output is correct |
11 |
Correct |
191 ms |
8220 KB |
Output is correct |
12 |
Correct |
182 ms |
8000 KB |
Output is correct |
13 |
Correct |
193 ms |
7924 KB |
Output is correct |
14 |
Correct |
208 ms |
8292 KB |
Output is correct |
15 |
Correct |
203 ms |
8252 KB |
Output is correct |
16 |
Correct |
10 ms |
4180 KB |
Output is correct |
17 |
Correct |
193 ms |
8084 KB |
Output is correct |
18 |
Correct |
187 ms |
7964 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
217 ms |
524288 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
204 ms |
524288 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
252 ms |
8456 KB |
Output is correct |
2 |
Correct |
210 ms |
8380 KB |
Output is correct |
3 |
Correct |
206 ms |
8140 KB |
Output is correct |
4 |
Correct |
186 ms |
8164 KB |
Output is correct |
5 |
Correct |
211 ms |
8380 KB |
Output is correct |
6 |
Correct |
184 ms |
7876 KB |
Output is correct |
7 |
Correct |
226 ms |
8308 KB |
Output is correct |
8 |
Correct |
182 ms |
7900 KB |
Output is correct |
9 |
Correct |
197 ms |
8136 KB |
Output is correct |
10 |
Correct |
187 ms |
8004 KB |
Output is correct |
11 |
Correct |
191 ms |
8220 KB |
Output is correct |
12 |
Correct |
182 ms |
8000 KB |
Output is correct |
13 |
Correct |
193 ms |
7924 KB |
Output is correct |
14 |
Correct |
208 ms |
8292 KB |
Output is correct |
15 |
Correct |
203 ms |
8252 KB |
Output is correct |
16 |
Correct |
10 ms |
4180 KB |
Output is correct |
17 |
Correct |
193 ms |
8084 KB |
Output is correct |
18 |
Correct |
187 ms |
7964 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Runtime error |
217 ms |
524288 KB |
Execution killed with signal 9 |
22 |
Halted |
0 ms |
0 KB |
- |