#include <bits/stdc++.h>
#include "bubblesort2.h"
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif
const int N = 15e5 + 5;
int SZ;
int s[4 * N], lz[4 * N], cnt[4 * N];
void app(int id, int x) {
s[id] -= x;
lz[id] += x;
}
void psh(int id) {
if (lz[id]) {
app(id * 2, lz[id]);
app(id * 2 + 1, lz[id]);
lz[id] = 0;
}
}
void upd(int i, int x, int id = 1, int l = 1, int r = SZ, int rank = 0) {
if (l == r) {
if (x == -1) {
s[id] = 0;
cnt[id] = 0;
} else {
s[id] = x - rank;
cnt[id] = 1;
}
return;
}
psh(id);
int md = (l + r) / 2;
if (i <= md) {
app(id * 2 + 1, x == -1 ? -1 : 1);
upd(i, x, id * 2, l, md, rank);
} else {
upd(i, x, id * 2 + 1, md + 1, r, rank + cnt[id * 2]);
}
cnt[id] = cnt[id * 2] + cnt[id * 2 + 1];
s[id] = max(s[id * 2], s[id * 2 + 1]);
}
vector<int> countScans(vector<int> A, vector<int> X, vector<int> V) {
int N = A.size(), Q = X.size();
vector<array<int, 2>> comp;
for (int i = 0; i < N; ++i) {
comp.push_back({A[i], i});
}
for (int i = 0; i < Q; ++i) {
comp.push_back({V[i], X[i]});
}
sort(comp.begin(), comp.end());
comp.erase(unique(comp.begin(), comp.end()), comp.end());
SZ = comp.size();
auto get = [&](int x, int i) {
return lower_bound(comp.begin(), comp.end(), array<int, 2>{x, i}) - comp.begin() + 1;
};
for (int i = 0; i < N; ++i) {
A[i] = get(A[i], i);
upd(A[i], i);
}
auto chg = [&](int u, int x) {
upd(A[u], -1);
A[u] = get(x, u);
upd(A[u], u);
};
vector<int> res(Q);
for (int i = 0; i < Q; ++i) {
chg(X[i], V[i]);
res[i] = s[1];
}
return res;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
476 KB |
Output is correct |
3 |
Correct |
2 ms |
652 KB |
Output is correct |
4 |
Correct |
2 ms |
604 KB |
Output is correct |
5 |
Correct |
3 ms |
444 KB |
Output is correct |
6 |
Correct |
2 ms |
604 KB |
Output is correct |
7 |
Correct |
2 ms |
604 KB |
Output is correct |
8 |
Correct |
3 ms |
604 KB |
Output is correct |
9 |
Correct |
3 ms |
604 KB |
Output is correct |
10 |
Correct |
2 ms |
704 KB |
Output is correct |
11 |
Correct |
3 ms |
604 KB |
Output is correct |
12 |
Correct |
2 ms |
604 KB |
Output is correct |
13 |
Correct |
3 ms |
604 KB |
Output is correct |
14 |
Correct |
2 ms |
604 KB |
Output is correct |
15 |
Correct |
4 ms |
604 KB |
Output is correct |
16 |
Correct |
2 ms |
464 KB |
Output is correct |
17 |
Correct |
4 ms |
604 KB |
Output is correct |
18 |
Correct |
2 ms |
604 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
476 KB |
Output is correct |
3 |
Correct |
2 ms |
652 KB |
Output is correct |
4 |
Correct |
2 ms |
604 KB |
Output is correct |
5 |
Correct |
3 ms |
444 KB |
Output is correct |
6 |
Correct |
2 ms |
604 KB |
Output is correct |
7 |
Correct |
2 ms |
604 KB |
Output is correct |
8 |
Correct |
3 ms |
604 KB |
Output is correct |
9 |
Correct |
3 ms |
604 KB |
Output is correct |
10 |
Correct |
2 ms |
704 KB |
Output is correct |
11 |
Correct |
3 ms |
604 KB |
Output is correct |
12 |
Correct |
2 ms |
604 KB |
Output is correct |
13 |
Correct |
3 ms |
604 KB |
Output is correct |
14 |
Correct |
2 ms |
604 KB |
Output is correct |
15 |
Correct |
4 ms |
604 KB |
Output is correct |
16 |
Correct |
2 ms |
464 KB |
Output is correct |
17 |
Correct |
4 ms |
604 KB |
Output is correct |
18 |
Correct |
2 ms |
604 KB |
Output is correct |
19 |
Correct |
8 ms |
1368 KB |
Output is correct |
20 |
Correct |
11 ms |
1476 KB |
Output is correct |
21 |
Correct |
9 ms |
1372 KB |
Output is correct |
22 |
Correct |
11 ms |
1372 KB |
Output is correct |
23 |
Correct |
14 ms |
1372 KB |
Output is correct |
24 |
Correct |
14 ms |
1372 KB |
Output is correct |
25 |
Correct |
8 ms |
1344 KB |
Output is correct |
26 |
Correct |
8 ms |
1372 KB |
Output is correct |
27 |
Correct |
9 ms |
1372 KB |
Output is correct |
28 |
Correct |
8 ms |
1372 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
1752 KB |
Output is correct |
2 |
Correct |
44 ms |
3648 KB |
Output is correct |
3 |
Correct |
91 ms |
6084 KB |
Output is correct |
4 |
Correct |
92 ms |
6180 KB |
Output is correct |
5 |
Correct |
66 ms |
6088 KB |
Output is correct |
6 |
Correct |
77 ms |
6244 KB |
Output is correct |
7 |
Correct |
69 ms |
6088 KB |
Output is correct |
8 |
Correct |
67 ms |
6192 KB |
Output is correct |
9 |
Correct |
67 ms |
6244 KB |
Output is correct |
10 |
Correct |
54 ms |
4672 KB |
Output is correct |
11 |
Correct |
53 ms |
4560 KB |
Output is correct |
12 |
Correct |
50 ms |
4552 KB |
Output is correct |
13 |
Correct |
57 ms |
4716 KB |
Output is correct |
14 |
Correct |
58 ms |
4632 KB |
Output is correct |
15 |
Correct |
51 ms |
4576 KB |
Output is correct |
16 |
Correct |
50 ms |
4744 KB |
Output is correct |
17 |
Correct |
49 ms |
4588 KB |
Output is correct |
18 |
Correct |
46 ms |
4560 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
476 KB |
Output is correct |
3 |
Correct |
2 ms |
652 KB |
Output is correct |
4 |
Correct |
2 ms |
604 KB |
Output is correct |
5 |
Correct |
3 ms |
444 KB |
Output is correct |
6 |
Correct |
2 ms |
604 KB |
Output is correct |
7 |
Correct |
2 ms |
604 KB |
Output is correct |
8 |
Correct |
3 ms |
604 KB |
Output is correct |
9 |
Correct |
3 ms |
604 KB |
Output is correct |
10 |
Correct |
2 ms |
704 KB |
Output is correct |
11 |
Correct |
3 ms |
604 KB |
Output is correct |
12 |
Correct |
2 ms |
604 KB |
Output is correct |
13 |
Correct |
3 ms |
604 KB |
Output is correct |
14 |
Correct |
2 ms |
604 KB |
Output is correct |
15 |
Correct |
4 ms |
604 KB |
Output is correct |
16 |
Correct |
2 ms |
464 KB |
Output is correct |
17 |
Correct |
4 ms |
604 KB |
Output is correct |
18 |
Correct |
2 ms |
604 KB |
Output is correct |
19 |
Correct |
8 ms |
1368 KB |
Output is correct |
20 |
Correct |
11 ms |
1476 KB |
Output is correct |
21 |
Correct |
9 ms |
1372 KB |
Output is correct |
22 |
Correct |
11 ms |
1372 KB |
Output is correct |
23 |
Correct |
14 ms |
1372 KB |
Output is correct |
24 |
Correct |
14 ms |
1372 KB |
Output is correct |
25 |
Correct |
8 ms |
1344 KB |
Output is correct |
26 |
Correct |
8 ms |
1372 KB |
Output is correct |
27 |
Correct |
9 ms |
1372 KB |
Output is correct |
28 |
Correct |
8 ms |
1372 KB |
Output is correct |
29 |
Correct |
15 ms |
1752 KB |
Output is correct |
30 |
Correct |
44 ms |
3648 KB |
Output is correct |
31 |
Correct |
91 ms |
6084 KB |
Output is correct |
32 |
Correct |
92 ms |
6180 KB |
Output is correct |
33 |
Correct |
66 ms |
6088 KB |
Output is correct |
34 |
Correct |
77 ms |
6244 KB |
Output is correct |
35 |
Correct |
69 ms |
6088 KB |
Output is correct |
36 |
Correct |
67 ms |
6192 KB |
Output is correct |
37 |
Correct |
67 ms |
6244 KB |
Output is correct |
38 |
Correct |
54 ms |
4672 KB |
Output is correct |
39 |
Correct |
53 ms |
4560 KB |
Output is correct |
40 |
Correct |
50 ms |
4552 KB |
Output is correct |
41 |
Correct |
57 ms |
4716 KB |
Output is correct |
42 |
Correct |
58 ms |
4632 KB |
Output is correct |
43 |
Correct |
51 ms |
4576 KB |
Output is correct |
44 |
Correct |
50 ms |
4744 KB |
Output is correct |
45 |
Correct |
49 ms |
4588 KB |
Output is correct |
46 |
Correct |
46 ms |
4560 KB |
Output is correct |
47 |
Correct |
262 ms |
22720 KB |
Output is correct |
48 |
Correct |
1121 ms |
56852 KB |
Output is correct |
49 |
Correct |
1304 ms |
59360 KB |
Output is correct |
50 |
Correct |
1213 ms |
59312 KB |
Output is correct |
51 |
Correct |
1281 ms |
59324 KB |
Output is correct |
52 |
Correct |
1264 ms |
59308 KB |
Output is correct |
53 |
Correct |
1187 ms |
59316 KB |
Output is correct |
54 |
Correct |
920 ms |
59444 KB |
Output is correct |
55 |
Correct |
953 ms |
59564 KB |
Output is correct |
56 |
Correct |
896 ms |
59568 KB |
Output is correct |
57 |
Correct |
924 ms |
59564 KB |
Output is correct |
58 |
Correct |
926 ms |
59568 KB |
Output is correct |
59 |
Correct |
781 ms |
58236 KB |
Output is correct |
60 |
Correct |
803 ms |
58248 KB |
Output is correct |
61 |
Correct |
778 ms |
58288 KB |
Output is correct |
62 |
Correct |
740 ms |
58040 KB |
Output is correct |
63 |
Correct |
717 ms |
58024 KB |
Output is correct |
64 |
Correct |
747 ms |
58032 KB |
Output is correct |
65 |
Correct |
707 ms |
58028 KB |
Output is correct |
66 |
Correct |
732 ms |
58032 KB |
Output is correct |
67 |
Correct |
800 ms |
58036 KB |
Output is correct |