#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];
}
void solve () {
cin >> n >> q;
for (int i = 1; i <= n; i++) cin >> a[i];
vt<pii> v;
int prv = -1, sub = 1;
while (q--) {
int t, i;
cin >> t >> i;
sub &= (prv == -1 || prv == t);
prv = t;
v.emplace_back(t, i);
}
for (auto [t, i]: v) {
for (int j = 1; j <= n; j++) b[j] = a[j];
while (t--) mergesort();
cout << b[i] << '\n';
}
cout << '\n';
}
bool testcases = 0;
signed main() {
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 |
Execution timed out |
3050 ms |
23836 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3041 ms |
38744 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3050 ms |
8248 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3050 ms |
23836 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |