#include "bubblesort2.h"
#include <bits/stdc++.h>
using namespace std;
using Arr = array<int, 3>;
const int N = 500500;
const int inf = 1e9;
int lz[N << 3];
int cnt[N << 3];
int val[N << 3];
void push(int v,int l,int r) {
if (lz[v]) {
val[v] += lz[v];
if (l < r) {
lz[v << 1] += lz[v];
lz[v << 1 | 1] += lz[v];
}
lz[v] = 0;
}
}
void upd(int v,int l,int r,int p,int x,int y) {
push(v, l, r);
if (p > r || p < l) return;
if (l == r) {
val[v] = x;
cnt[v] = y;
return;
}
int md = (l + r) >> 1;
upd(v << 1, l, md, p, x, y);
upd(v << 1 | 1, md + 1, r, p, x, y);
val[v] = max(val[v << 1], val[v << 1 | 1]);
cnt[v] = cnt[v << 1] + cnt[v << 1 | 1];
}
void add(int v,int l,int r,int L,int R,int x) {
push(v, l, r);
if (L > r || R < l) return;
if (L <= l && r <= R) {
lz[v] = x;
push(v, l, r);
return;
}
int md = (l + r) >> 1;
add(v << 1, l, md, L, R, x);
add(v << 1 | 1, md + 1, r, L, R, x);
val[v] = max(val[v << 1], val[v << 1 | 1]);
}
int get(int v,int l,int r,int L,int R) {
push(v, l, r);
if (L > r || R < l) return 0;
if (L <= l && r <= R) return cnt[v];
int md = (l + r) >> 1;
return get(v << 1, l, md, L, R) + get(v << 1 | 1, md + 1, r, L, R);
}
int now[N], pos[N];
vector<int> countScans(vector<int> a, vector<int> x, vector<int> y) {
int n = a.size(), q = x.size();
vector<Arr> vals;
for (int i = 0; i < n; ++i) {
vals.push_back({a[i], i, i});
}
for (int i = 0; i < q; ++i) {
vals.push_back({y[i], x[i], i + n});
}
sort(vals.begin(), vals.end());
int sz = n + q;
memset(val, -69, sizeof val);
for (int i = 0; i < sz; ++i) {
int p = vals[i][1], id = vals[i][2];
if (id >= n) {
pos[id - n] = i;
} else {
int nw = p - get(1, 0, sz - 1, 0, i);
now[p] = i;
upd(1, 0, sz - 1, i, nw, 1);
}
}
vector<int> ans(q);
for (int i = 0; i < q; ++i) {
add(1, 0, sz - 1, now[x[i]], sz - 1, 1);
upd(1, 0, sz - 1, now[x[i]], -inf, 0);
now[x[i]] = pos[i];
int nw = x[i] - get(1, 0, sz - 1, 0, now[x[i]]);
add(1, 0, sz - 1, now[x[i]], sz - 1, -1);
upd(1, 0, sz - 1, now[x[i]], nw, 1);
ans[i] = val[1];
}
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
16128 KB |
Output is correct |
2 |
Correct |
15 ms |
16128 KB |
Output is correct |
3 |
Correct |
19 ms |
16376 KB |
Output is correct |
4 |
Correct |
19 ms |
16256 KB |
Output is correct |
5 |
Correct |
19 ms |
16248 KB |
Output is correct |
6 |
Correct |
23 ms |
16256 KB |
Output is correct |
7 |
Correct |
19 ms |
16384 KB |
Output is correct |
8 |
Correct |
20 ms |
16256 KB |
Output is correct |
9 |
Correct |
18 ms |
16256 KB |
Output is correct |
10 |
Correct |
22 ms |
16256 KB |
Output is correct |
11 |
Correct |
20 ms |
16244 KB |
Output is correct |
12 |
Correct |
19 ms |
16256 KB |
Output is correct |
13 |
Correct |
19 ms |
16376 KB |
Output is correct |
14 |
Correct |
20 ms |
16256 KB |
Output is correct |
15 |
Correct |
20 ms |
16256 KB |
Output is correct |
16 |
Correct |
22 ms |
16256 KB |
Output is correct |
17 |
Correct |
18 ms |
16256 KB |
Output is correct |
18 |
Correct |
20 ms |
16228 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
16128 KB |
Output is correct |
2 |
Correct |
15 ms |
16128 KB |
Output is correct |
3 |
Correct |
19 ms |
16376 KB |
Output is correct |
4 |
Correct |
19 ms |
16256 KB |
Output is correct |
5 |
Correct |
19 ms |
16248 KB |
Output is correct |
6 |
Correct |
23 ms |
16256 KB |
Output is correct |
7 |
Correct |
19 ms |
16384 KB |
Output is correct |
8 |
Correct |
20 ms |
16256 KB |
Output is correct |
9 |
Correct |
18 ms |
16256 KB |
Output is correct |
10 |
Correct |
22 ms |
16256 KB |
Output is correct |
11 |
Correct |
20 ms |
16244 KB |
Output is correct |
12 |
Correct |
19 ms |
16256 KB |
Output is correct |
13 |
Correct |
19 ms |
16376 KB |
Output is correct |
14 |
Correct |
20 ms |
16256 KB |
Output is correct |
15 |
Correct |
20 ms |
16256 KB |
Output is correct |
16 |
Correct |
22 ms |
16256 KB |
Output is correct |
17 |
Correct |
18 ms |
16256 KB |
Output is correct |
18 |
Correct |
20 ms |
16228 KB |
Output is correct |
19 |
Correct |
33 ms |
16960 KB |
Output is correct |
20 |
Correct |
33 ms |
16952 KB |
Output is correct |
21 |
Correct |
34 ms |
16952 KB |
Output is correct |
22 |
Correct |
31 ms |
16952 KB |
Output is correct |
23 |
Correct |
33 ms |
16960 KB |
Output is correct |
24 |
Correct |
30 ms |
16960 KB |
Output is correct |
25 |
Correct |
32 ms |
16984 KB |
Output is correct |
26 |
Correct |
33 ms |
16952 KB |
Output is correct |
27 |
Correct |
32 ms |
16960 KB |
Output is correct |
28 |
Correct |
36 ms |
16952 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
37 ms |
17396 KB |
Output is correct |
2 |
Correct |
96 ms |
18928 KB |
Output is correct |
3 |
Correct |
217 ms |
21100 KB |
Output is correct |
4 |
Correct |
167 ms |
21200 KB |
Output is correct |
5 |
Correct |
189 ms |
21376 KB |
Output is correct |
6 |
Correct |
210 ms |
21260 KB |
Output is correct |
7 |
Correct |
186 ms |
21356 KB |
Output is correct |
8 |
Correct |
184 ms |
21356 KB |
Output is correct |
9 |
Correct |
186 ms |
21232 KB |
Output is correct |
10 |
Correct |
183 ms |
21232 KB |
Output is correct |
11 |
Correct |
167 ms |
21360 KB |
Output is correct |
12 |
Correct |
148 ms |
21228 KB |
Output is correct |
13 |
Correct |
148 ms |
21228 KB |
Output is correct |
14 |
Correct |
145 ms |
21228 KB |
Output is correct |
15 |
Correct |
150 ms |
21244 KB |
Output is correct |
16 |
Correct |
148 ms |
20816 KB |
Output is correct |
17 |
Correct |
153 ms |
20768 KB |
Output is correct |
18 |
Correct |
146 ms |
20844 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
16128 KB |
Output is correct |
2 |
Correct |
15 ms |
16128 KB |
Output is correct |
3 |
Correct |
19 ms |
16376 KB |
Output is correct |
4 |
Correct |
19 ms |
16256 KB |
Output is correct |
5 |
Correct |
19 ms |
16248 KB |
Output is correct |
6 |
Correct |
23 ms |
16256 KB |
Output is correct |
7 |
Correct |
19 ms |
16384 KB |
Output is correct |
8 |
Correct |
20 ms |
16256 KB |
Output is correct |
9 |
Correct |
18 ms |
16256 KB |
Output is correct |
10 |
Correct |
22 ms |
16256 KB |
Output is correct |
11 |
Correct |
20 ms |
16244 KB |
Output is correct |
12 |
Correct |
19 ms |
16256 KB |
Output is correct |
13 |
Correct |
19 ms |
16376 KB |
Output is correct |
14 |
Correct |
20 ms |
16256 KB |
Output is correct |
15 |
Correct |
20 ms |
16256 KB |
Output is correct |
16 |
Correct |
22 ms |
16256 KB |
Output is correct |
17 |
Correct |
18 ms |
16256 KB |
Output is correct |
18 |
Correct |
20 ms |
16228 KB |
Output is correct |
19 |
Correct |
33 ms |
16960 KB |
Output is correct |
20 |
Correct |
33 ms |
16952 KB |
Output is correct |
21 |
Correct |
34 ms |
16952 KB |
Output is correct |
22 |
Correct |
31 ms |
16952 KB |
Output is correct |
23 |
Correct |
33 ms |
16960 KB |
Output is correct |
24 |
Correct |
30 ms |
16960 KB |
Output is correct |
25 |
Correct |
32 ms |
16984 KB |
Output is correct |
26 |
Correct |
33 ms |
16952 KB |
Output is correct |
27 |
Correct |
32 ms |
16960 KB |
Output is correct |
28 |
Correct |
36 ms |
16952 KB |
Output is correct |
29 |
Correct |
37 ms |
17396 KB |
Output is correct |
30 |
Correct |
96 ms |
18928 KB |
Output is correct |
31 |
Correct |
217 ms |
21100 KB |
Output is correct |
32 |
Correct |
167 ms |
21200 KB |
Output is correct |
33 |
Correct |
189 ms |
21376 KB |
Output is correct |
34 |
Correct |
210 ms |
21260 KB |
Output is correct |
35 |
Correct |
186 ms |
21356 KB |
Output is correct |
36 |
Correct |
184 ms |
21356 KB |
Output is correct |
37 |
Correct |
186 ms |
21232 KB |
Output is correct |
38 |
Correct |
183 ms |
21232 KB |
Output is correct |
39 |
Correct |
167 ms |
21360 KB |
Output is correct |
40 |
Correct |
148 ms |
21228 KB |
Output is correct |
41 |
Correct |
148 ms |
21228 KB |
Output is correct |
42 |
Correct |
145 ms |
21228 KB |
Output is correct |
43 |
Correct |
150 ms |
21244 KB |
Output is correct |
44 |
Correct |
148 ms |
20816 KB |
Output is correct |
45 |
Correct |
153 ms |
20768 KB |
Output is correct |
46 |
Correct |
146 ms |
20844 KB |
Output is correct |
47 |
Correct |
598 ms |
33116 KB |
Output is correct |
48 |
Correct |
2471 ms |
59852 KB |
Output is correct |
49 |
Correct |
2681 ms |
62156 KB |
Output is correct |
50 |
Correct |
2874 ms |
62136 KB |
Output is correct |
51 |
Correct |
2783 ms |
62384 KB |
Output is correct |
52 |
Correct |
2687 ms |
62284 KB |
Output is correct |
53 |
Correct |
2941 ms |
62284 KB |
Output is correct |
54 |
Correct |
2558 ms |
62324 KB |
Output is correct |
55 |
Correct |
2815 ms |
62156 KB |
Output is correct |
56 |
Correct |
2568 ms |
62284 KB |
Output is correct |
57 |
Correct |
2672 ms |
62284 KB |
Output is correct |
58 |
Correct |
2680 ms |
62164 KB |
Output is correct |
59 |
Correct |
2252 ms |
62284 KB |
Output is correct |
60 |
Correct |
2437 ms |
62164 KB |
Output is correct |
61 |
Correct |
2264 ms |
62256 KB |
Output is correct |
62 |
Correct |
2012 ms |
62308 KB |
Output is correct |
63 |
Correct |
2027 ms |
62288 KB |
Output is correct |
64 |
Correct |
2281 ms |
62112 KB |
Output is correct |
65 |
Correct |
1974 ms |
62156 KB |
Output is correct |
66 |
Correct |
2021 ms |
62088 KB |
Output is correct |
67 |
Correct |
2110 ms |
62156 KB |
Output is correct |