#pragma GCC optimize("O3", "unroll-loops") // "Ofast"
#pragma GCC target("avx2", "bmi", "bmi2", "lzcnt", "popcnt")
#include <bits/stdc++.h>
#define int long long
#define vt vector
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
#define f first
#define s second
#define dbg(x) cerr << #x << " = " << x << '\n'
#define bit(x, i) ((x) >> (i) & 1)
using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
const int N = 1e6 + 5, mod = 1e9 + 7;
const ll inf = 1e18 + 7;
const ld eps = 1e-6;
ll add (ll a, ll b) {
a += b;
if (a < 0) a += mod;
if (a >= mod) a -= mod;
return a;
}
ll mul (ll a, ll b) {
a *= b;
if (a >= mod) a %= mod;
return a;
}
int n, q, a[N], b[N];
void mergesort () {
vt<int> L, R, res;
for (int i = 1; i <= n; i++) {
if (i <= n / 2) L.pb(b[i]);
else R.pb(b[i]);
}
int i = 0, j = 0;
while (i < sz(L) && j < sz(R)) {
if (L[i] < R[j]) res.pb(L[i]), i++;
else res.pb(R[j]), j++;
}
while (i < sz(L)) res.pb(L[i]), i++;
while (j < sz(R)) res.pb(R[j]), j++;
for (i = 1; i <= n; i++) b[i] = res[i - 1];
}
vt<int> res[N];
void solve () {
cin >> n >> q;
for (int i = 1; i <= n; i++) cin >> a[i];
vt<pii> v;
int prv = -1, sub = 1, mx = 0;
while (q--) {
int t, i;
cin >> t >> i;
sub &= (prv == -1 || prv == t);
prv = t;
v.emplace_back(min(t, 1000ll), i - 1);
mx = max(mx, t);
}
for (int i = 1; i <= n; i++) b[i] = a[i], res[0].pb(a[i]);
for (int it = 1; it <= min(mx, 1000ll); it++) {
mergesort();
for (int j = 1; j <= n; j++) res[it].pb(b[j]);
}
for (auto [t, i]: v) cout << res[t][i] << '\n';
cout << '\n';
}
bool testcases = 0;
signed main() {
/*#ifndef ONLINE_JUDGE
freopen(".in", "r", stdin);
freopen(".out", "w", stdout);
#endif*/
cin.tie(0) -> sync_with_stdio(0);
int test = 1;
if (testcases) cin >> test;
for (int cs = 1; cs <= test; cs++) {
solve();
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
283 ms |
51616 KB |
Output is correct |
2 |
Correct |
309 ms |
51724 KB |
Output is correct |
3 |
Correct |
256 ms |
50920 KB |
Output is correct |
4 |
Correct |
201 ms |
50684 KB |
Output is correct |
5 |
Correct |
216 ms |
51560 KB |
Output is correct |
6 |
Correct |
229 ms |
50840 KB |
Output is correct |
7 |
Correct |
224 ms |
51608 KB |
Output is correct |
8 |
Correct |
220 ms |
50892 KB |
Output is correct |
9 |
Correct |
214 ms |
50744 KB |
Output is correct |
10 |
Correct |
208 ms |
51096 KB |
Output is correct |
11 |
Correct |
208 ms |
51020 KB |
Output is correct |
12 |
Correct |
211 ms |
50732 KB |
Output is correct |
13 |
Correct |
219 ms |
51176 KB |
Output is correct |
14 |
Correct |
218 ms |
51304 KB |
Output is correct |
15 |
Correct |
215 ms |
51576 KB |
Output is correct |
16 |
Correct |
16 ms |
23876 KB |
Output is correct |
17 |
Correct |
205 ms |
50996 KB |
Output is correct |
18 |
Correct |
207 ms |
50912 KB |
Output is correct |
19 |
Correct |
14 ms |
23764 KB |
Output is correct |
20 |
Correct |
14 ms |
23816 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
965 ms |
524288 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1158 ms |
524288 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
283 ms |
51616 KB |
Output is correct |
2 |
Correct |
309 ms |
51724 KB |
Output is correct |
3 |
Correct |
256 ms |
50920 KB |
Output is correct |
4 |
Correct |
201 ms |
50684 KB |
Output is correct |
5 |
Correct |
216 ms |
51560 KB |
Output is correct |
6 |
Correct |
229 ms |
50840 KB |
Output is correct |
7 |
Correct |
224 ms |
51608 KB |
Output is correct |
8 |
Correct |
220 ms |
50892 KB |
Output is correct |
9 |
Correct |
214 ms |
50744 KB |
Output is correct |
10 |
Correct |
208 ms |
51096 KB |
Output is correct |
11 |
Correct |
208 ms |
51020 KB |
Output is correct |
12 |
Correct |
211 ms |
50732 KB |
Output is correct |
13 |
Correct |
219 ms |
51176 KB |
Output is correct |
14 |
Correct |
218 ms |
51304 KB |
Output is correct |
15 |
Correct |
215 ms |
51576 KB |
Output is correct |
16 |
Correct |
16 ms |
23876 KB |
Output is correct |
17 |
Correct |
205 ms |
50996 KB |
Output is correct |
18 |
Correct |
207 ms |
50912 KB |
Output is correct |
19 |
Correct |
14 ms |
23764 KB |
Output is correct |
20 |
Correct |
14 ms |
23816 KB |
Output is correct |
21 |
Runtime error |
965 ms |
524288 KB |
Execution killed with signal 9 |
22 |
Halted |
0 ms |
0 KB |
- |