#include <bits/stdc++.h>
using namespace std;
const int N = 1000000;
array<int, 2> values[N];
int maxi[4 * N], lazy[4 * N], m;
void update(int a, int b, int x, int u = 1, int l = 0, int r = m - 1) {
if (a > b || b < l || r < a) {
return;
} else if (a <= l && r <= b) {
lazy[u] += x;
maxi[u] += x;
} else {
int m = (l + r) / 2;
update(a, b, x, 2 * u, l, m);
update(a, b, x, 2 * u + 1, m + 1, r);
maxi[u] = max(maxi[2 * u], maxi[2 * u + 1]) + lazy[u];
}
}
void assign(int a, int x, int u = 1, int l = 0, int r = m - 1) {
if (l == r) {
maxi[u] = x + lazy[u];
} else {
int m = (l + r) / 2;
if (a <= m) {
assign(a, x, 2 * u, l, m);
} else {
assign(a, x, 2 * u + 1, m + 1, r);
}
maxi[u] = max(maxi[2 * u], maxi[2 * u + 1]) + lazy[u];
}
}
void insert(int a, int i, int k) {
a = lower_bound(values, values + m, array<int, 2>{a, i}) - values;
update(a + 1, m - 1, k);
assign(a, k == 1 ? 0 : i);
}
vector<int> countScans(vector<int> a, vector<int> x, vector<int> v) {
int n = a.size(), q = x.size();
for (int i = 0; i < n; ++i) {
values[i] = {a[i], i};
}
for (int i = 0; i < q; ++i) {
values[n + i] = {v[i], x[i]};
}
sort(values, values + n + q);
m = unique(values, values + n + q) - values;
for (int i = 0; i < n; ++i) {
insert(a[i], i, -1);
}
vector<int> ans(q);
for (int i = 0; i < q; ++i) {
insert(a[x[i]], x[i], 1);
a[x[i]] = v[i];
insert(v[i], x[i], -1);
ans[i] = maxi[1];
}
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
332 KB |
Output is correct |
2 |
Correct |
3 ms |
316 KB |
Output is correct |
3 |
Correct |
5 ms |
460 KB |
Output is correct |
4 |
Correct |
5 ms |
472 KB |
Output is correct |
5 |
Correct |
5 ms |
460 KB |
Output is correct |
6 |
Correct |
5 ms |
460 KB |
Output is correct |
7 |
Correct |
5 ms |
460 KB |
Output is correct |
8 |
Correct |
5 ms |
484 KB |
Output is correct |
9 |
Correct |
5 ms |
460 KB |
Output is correct |
10 |
Correct |
5 ms |
460 KB |
Output is correct |
11 |
Correct |
5 ms |
464 KB |
Output is correct |
12 |
Correct |
5 ms |
460 KB |
Output is correct |
13 |
Correct |
5 ms |
460 KB |
Output is correct |
14 |
Correct |
5 ms |
460 KB |
Output is correct |
15 |
Correct |
5 ms |
460 KB |
Output is correct |
16 |
Correct |
4 ms |
444 KB |
Output is correct |
17 |
Correct |
4 ms |
444 KB |
Output is correct |
18 |
Correct |
5 ms |
512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
332 KB |
Output is correct |
2 |
Correct |
3 ms |
316 KB |
Output is correct |
3 |
Correct |
5 ms |
460 KB |
Output is correct |
4 |
Correct |
5 ms |
472 KB |
Output is correct |
5 |
Correct |
5 ms |
460 KB |
Output is correct |
6 |
Correct |
5 ms |
460 KB |
Output is correct |
7 |
Correct |
5 ms |
460 KB |
Output is correct |
8 |
Correct |
5 ms |
484 KB |
Output is correct |
9 |
Correct |
5 ms |
460 KB |
Output is correct |
10 |
Correct |
5 ms |
460 KB |
Output is correct |
11 |
Correct |
5 ms |
464 KB |
Output is correct |
12 |
Correct |
5 ms |
460 KB |
Output is correct |
13 |
Correct |
5 ms |
460 KB |
Output is correct |
14 |
Correct |
5 ms |
460 KB |
Output is correct |
15 |
Correct |
5 ms |
460 KB |
Output is correct |
16 |
Correct |
4 ms |
444 KB |
Output is correct |
17 |
Correct |
4 ms |
444 KB |
Output is correct |
18 |
Correct |
5 ms |
512 KB |
Output is correct |
19 |
Correct |
17 ms |
972 KB |
Output is correct |
20 |
Correct |
19 ms |
1116 KB |
Output is correct |
21 |
Correct |
19 ms |
1088 KB |
Output is correct |
22 |
Correct |
19 ms |
1148 KB |
Output is correct |
23 |
Correct |
21 ms |
1020 KB |
Output is correct |
24 |
Correct |
19 ms |
1016 KB |
Output is correct |
25 |
Correct |
18 ms |
1100 KB |
Output is correct |
26 |
Correct |
18 ms |
1104 KB |
Output is correct |
27 |
Correct |
18 ms |
1076 KB |
Output is correct |
28 |
Correct |
18 ms |
1092 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
26 ms |
1408 KB |
Output is correct |
2 |
Correct |
78 ms |
2884 KB |
Output is correct |
3 |
Correct |
144 ms |
5092 KB |
Output is correct |
4 |
Correct |
138 ms |
5092 KB |
Output is correct |
5 |
Correct |
138 ms |
5032 KB |
Output is correct |
6 |
Correct |
138 ms |
5060 KB |
Output is correct |
7 |
Correct |
138 ms |
5036 KB |
Output is correct |
8 |
Correct |
143 ms |
5080 KB |
Output is correct |
9 |
Correct |
139 ms |
5060 KB |
Output is correct |
10 |
Correct |
114 ms |
4124 KB |
Output is correct |
11 |
Correct |
115 ms |
4084 KB |
Output is correct |
12 |
Correct |
113 ms |
4036 KB |
Output is correct |
13 |
Correct |
113 ms |
4084 KB |
Output is correct |
14 |
Correct |
115 ms |
4072 KB |
Output is correct |
15 |
Correct |
115 ms |
4208 KB |
Output is correct |
16 |
Correct |
107 ms |
4116 KB |
Output is correct |
17 |
Correct |
108 ms |
4084 KB |
Output is correct |
18 |
Correct |
106 ms |
4028 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
332 KB |
Output is correct |
2 |
Correct |
3 ms |
316 KB |
Output is correct |
3 |
Correct |
5 ms |
460 KB |
Output is correct |
4 |
Correct |
5 ms |
472 KB |
Output is correct |
5 |
Correct |
5 ms |
460 KB |
Output is correct |
6 |
Correct |
5 ms |
460 KB |
Output is correct |
7 |
Correct |
5 ms |
460 KB |
Output is correct |
8 |
Correct |
5 ms |
484 KB |
Output is correct |
9 |
Correct |
5 ms |
460 KB |
Output is correct |
10 |
Correct |
5 ms |
460 KB |
Output is correct |
11 |
Correct |
5 ms |
464 KB |
Output is correct |
12 |
Correct |
5 ms |
460 KB |
Output is correct |
13 |
Correct |
5 ms |
460 KB |
Output is correct |
14 |
Correct |
5 ms |
460 KB |
Output is correct |
15 |
Correct |
5 ms |
460 KB |
Output is correct |
16 |
Correct |
4 ms |
444 KB |
Output is correct |
17 |
Correct |
4 ms |
444 KB |
Output is correct |
18 |
Correct |
5 ms |
512 KB |
Output is correct |
19 |
Correct |
17 ms |
972 KB |
Output is correct |
20 |
Correct |
19 ms |
1116 KB |
Output is correct |
21 |
Correct |
19 ms |
1088 KB |
Output is correct |
22 |
Correct |
19 ms |
1148 KB |
Output is correct |
23 |
Correct |
21 ms |
1020 KB |
Output is correct |
24 |
Correct |
19 ms |
1016 KB |
Output is correct |
25 |
Correct |
18 ms |
1100 KB |
Output is correct |
26 |
Correct |
18 ms |
1104 KB |
Output is correct |
27 |
Correct |
18 ms |
1076 KB |
Output is correct |
28 |
Correct |
18 ms |
1092 KB |
Output is correct |
29 |
Correct |
26 ms |
1408 KB |
Output is correct |
30 |
Correct |
78 ms |
2884 KB |
Output is correct |
31 |
Correct |
144 ms |
5092 KB |
Output is correct |
32 |
Correct |
138 ms |
5092 KB |
Output is correct |
33 |
Correct |
138 ms |
5032 KB |
Output is correct |
34 |
Correct |
138 ms |
5060 KB |
Output is correct |
35 |
Correct |
138 ms |
5036 KB |
Output is correct |
36 |
Correct |
143 ms |
5080 KB |
Output is correct |
37 |
Correct |
139 ms |
5060 KB |
Output is correct |
38 |
Correct |
114 ms |
4124 KB |
Output is correct |
39 |
Correct |
115 ms |
4084 KB |
Output is correct |
40 |
Correct |
113 ms |
4036 KB |
Output is correct |
41 |
Correct |
113 ms |
4084 KB |
Output is correct |
42 |
Correct |
115 ms |
4072 KB |
Output is correct |
43 |
Correct |
115 ms |
4208 KB |
Output is correct |
44 |
Correct |
107 ms |
4116 KB |
Output is correct |
45 |
Correct |
108 ms |
4084 KB |
Output is correct |
46 |
Correct |
106 ms |
4028 KB |
Output is correct |
47 |
Correct |
525 ms |
18544 KB |
Output is correct |
48 |
Correct |
2241 ms |
48568 KB |
Output is correct |
49 |
Correct |
2383 ms |
51272 KB |
Output is correct |
50 |
Correct |
2384 ms |
51156 KB |
Output is correct |
51 |
Correct |
2364 ms |
51276 KB |
Output is correct |
52 |
Correct |
2420 ms |
51156 KB |
Output is correct |
53 |
Correct |
2429 ms |
51116 KB |
Output is correct |
54 |
Correct |
2160 ms |
51304 KB |
Output is correct |
55 |
Correct |
2304 ms |
51260 KB |
Output is correct |
56 |
Correct |
2141 ms |
51296 KB |
Output is correct |
57 |
Correct |
2231 ms |
51432 KB |
Output is correct |
58 |
Correct |
2104 ms |
51296 KB |
Output is correct |
59 |
Correct |
1984 ms |
49968 KB |
Output is correct |
60 |
Correct |
2066 ms |
49972 KB |
Output is correct |
61 |
Correct |
2126 ms |
49864 KB |
Output is correct |
62 |
Correct |
2045 ms |
49828 KB |
Output is correct |
63 |
Correct |
1908 ms |
49836 KB |
Output is correct |
64 |
Correct |
1929 ms |
49832 KB |
Output is correct |
65 |
Correct |
1801 ms |
49692 KB |
Output is correct |
66 |
Correct |
1813 ms |
49688 KB |
Output is correct |
67 |
Correct |
1787 ms |
49688 KB |
Output is correct |