#include "bubblesort2.h"
#include <bits/stdc++.h>
#define FOR(i, x, y) for (int i = x; i < y; i++)
typedef long long ll;
using namespace std;
const int INF = INT_MAX / 2;
int N, S;
int segtree[4000000], lazy[4000000];
void push_lazy(int node, int l, int r) {
segtree[node] += lazy[node];
if (l != r) {
lazy[node * 2] += lazy[node];
lazy[node * 2 + 1] += lazy[node];
}
lazy[node] = 0;
}
int query(int node) {
return segtree[node] + lazy[node];
}
void update(int a, int b, int val, int node = 1, int l = 0, int r = S) {
if (a == b || a >= r || b <= l) return;
if (a <= l && b >= r) {
lazy[node] += val;
return;
}
push_lazy(node, l, r);
int mid = (l + r) / 2;
update(a, b, val, node * 2, l, mid);
update(a, b, val, node * 2 + 1, mid, r);
segtree[node] = max(query(node * 2), query(node * 2 + 1));
}
vector<int> countScans(vector<int> A, vector<int> X, vector<int> V) {
int Q = X.size();
N = A.size();
vector<int> answer(Q);
vector<pair<int, int>> compressed;
FOR(i, 0, N) compressed.push_back({A[i], i});
FOR(i, 0, Q) compressed.push_back({V[i], X[i]});
sort(compressed.begin(), compressed.end());
compressed.erase(unique(compressed.begin(), compressed.end()), compressed.end());
const auto insert = [&](int a, int b) {
int pos = lower_bound(compressed.begin(), compressed.end(), make_pair(a, b)) - compressed.begin();
update(pos, pos + 1, INF + b);
update(pos + 1, S, -1);
};
const auto erase = [&](int a, int b) {
int pos = lower_bound(compressed.begin(), compressed.end(), make_pair(a, b)) - compressed.begin();
update(pos, pos + 1, -(INF + b));
update(pos + 1, S, 1);
};
S = compressed.size();
update(0, S, -INF);
FOR(i, 0, N) insert(A[i], i);
FOR(i, 0, Q) {
erase(A[X[i]], X[i]);
insert(V[i], X[i]);
A[X[i]] = V[i];
answer[i] = query(1);
}
return answer;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
376 KB |
Output is correct |
2 |
Correct |
4 ms |
376 KB |
Output is correct |
3 |
Correct |
7 ms |
504 KB |
Output is correct |
4 |
Correct |
7 ms |
632 KB |
Output is correct |
5 |
Correct |
7 ms |
632 KB |
Output is correct |
6 |
Correct |
7 ms |
508 KB |
Output is correct |
7 |
Correct |
7 ms |
632 KB |
Output is correct |
8 |
Correct |
7 ms |
636 KB |
Output is correct |
9 |
Correct |
7 ms |
504 KB |
Output is correct |
10 |
Correct |
7 ms |
504 KB |
Output is correct |
11 |
Correct |
7 ms |
504 KB |
Output is correct |
12 |
Correct |
6 ms |
504 KB |
Output is correct |
13 |
Correct |
7 ms |
584 KB |
Output is correct |
14 |
Correct |
6 ms |
500 KB |
Output is correct |
15 |
Correct |
6 ms |
504 KB |
Output is correct |
16 |
Correct |
6 ms |
504 KB |
Output is correct |
17 |
Correct |
8 ms |
632 KB |
Output is correct |
18 |
Correct |
6 ms |
632 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
376 KB |
Output is correct |
2 |
Correct |
4 ms |
376 KB |
Output is correct |
3 |
Correct |
7 ms |
504 KB |
Output is correct |
4 |
Correct |
7 ms |
632 KB |
Output is correct |
5 |
Correct |
7 ms |
632 KB |
Output is correct |
6 |
Correct |
7 ms |
508 KB |
Output is correct |
7 |
Correct |
7 ms |
632 KB |
Output is correct |
8 |
Correct |
7 ms |
636 KB |
Output is correct |
9 |
Correct |
7 ms |
504 KB |
Output is correct |
10 |
Correct |
7 ms |
504 KB |
Output is correct |
11 |
Correct |
7 ms |
504 KB |
Output is correct |
12 |
Correct |
6 ms |
504 KB |
Output is correct |
13 |
Correct |
7 ms |
584 KB |
Output is correct |
14 |
Correct |
6 ms |
500 KB |
Output is correct |
15 |
Correct |
6 ms |
504 KB |
Output is correct |
16 |
Correct |
6 ms |
504 KB |
Output is correct |
17 |
Correct |
8 ms |
632 KB |
Output is correct |
18 |
Correct |
6 ms |
632 KB |
Output is correct |
19 |
Correct |
21 ms |
1148 KB |
Output is correct |
20 |
Correct |
23 ms |
1144 KB |
Output is correct |
21 |
Correct |
23 ms |
1272 KB |
Output is correct |
22 |
Correct |
23 ms |
1272 KB |
Output is correct |
23 |
Correct |
22 ms |
1144 KB |
Output is correct |
24 |
Correct |
25 ms |
1144 KB |
Output is correct |
25 |
Correct |
22 ms |
1144 KB |
Output is correct |
26 |
Correct |
22 ms |
1144 KB |
Output is correct |
27 |
Correct |
21 ms |
1144 KB |
Output is correct |
28 |
Correct |
22 ms |
1144 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
30 ms |
1400 KB |
Output is correct |
2 |
Correct |
90 ms |
2832 KB |
Output is correct |
3 |
Correct |
164 ms |
4716 KB |
Output is correct |
4 |
Correct |
173 ms |
4716 KB |
Output is correct |
5 |
Correct |
161 ms |
4900 KB |
Output is correct |
6 |
Correct |
163 ms |
4728 KB |
Output is correct |
7 |
Correct |
159 ms |
4844 KB |
Output is correct |
8 |
Correct |
165 ms |
4856 KB |
Output is correct |
9 |
Correct |
171 ms |
4780 KB |
Output is correct |
10 |
Correct |
131 ms |
4076 KB |
Output is correct |
11 |
Correct |
132 ms |
4076 KB |
Output is correct |
12 |
Correct |
132 ms |
4084 KB |
Output is correct |
13 |
Correct |
129 ms |
4076 KB |
Output is correct |
14 |
Correct |
128 ms |
4076 KB |
Output is correct |
15 |
Correct |
129 ms |
4076 KB |
Output is correct |
16 |
Correct |
122 ms |
3952 KB |
Output is correct |
17 |
Correct |
129 ms |
4004 KB |
Output is correct |
18 |
Correct |
121 ms |
4076 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
376 KB |
Output is correct |
2 |
Correct |
4 ms |
376 KB |
Output is correct |
3 |
Correct |
7 ms |
504 KB |
Output is correct |
4 |
Correct |
7 ms |
632 KB |
Output is correct |
5 |
Correct |
7 ms |
632 KB |
Output is correct |
6 |
Correct |
7 ms |
508 KB |
Output is correct |
7 |
Correct |
7 ms |
632 KB |
Output is correct |
8 |
Correct |
7 ms |
636 KB |
Output is correct |
9 |
Correct |
7 ms |
504 KB |
Output is correct |
10 |
Correct |
7 ms |
504 KB |
Output is correct |
11 |
Correct |
7 ms |
504 KB |
Output is correct |
12 |
Correct |
6 ms |
504 KB |
Output is correct |
13 |
Correct |
7 ms |
584 KB |
Output is correct |
14 |
Correct |
6 ms |
500 KB |
Output is correct |
15 |
Correct |
6 ms |
504 KB |
Output is correct |
16 |
Correct |
6 ms |
504 KB |
Output is correct |
17 |
Correct |
8 ms |
632 KB |
Output is correct |
18 |
Correct |
6 ms |
632 KB |
Output is correct |
19 |
Correct |
21 ms |
1148 KB |
Output is correct |
20 |
Correct |
23 ms |
1144 KB |
Output is correct |
21 |
Correct |
23 ms |
1272 KB |
Output is correct |
22 |
Correct |
23 ms |
1272 KB |
Output is correct |
23 |
Correct |
22 ms |
1144 KB |
Output is correct |
24 |
Correct |
25 ms |
1144 KB |
Output is correct |
25 |
Correct |
22 ms |
1144 KB |
Output is correct |
26 |
Correct |
22 ms |
1144 KB |
Output is correct |
27 |
Correct |
21 ms |
1144 KB |
Output is correct |
28 |
Correct |
22 ms |
1144 KB |
Output is correct |
29 |
Correct |
30 ms |
1400 KB |
Output is correct |
30 |
Correct |
90 ms |
2832 KB |
Output is correct |
31 |
Correct |
164 ms |
4716 KB |
Output is correct |
32 |
Correct |
173 ms |
4716 KB |
Output is correct |
33 |
Correct |
161 ms |
4900 KB |
Output is correct |
34 |
Correct |
163 ms |
4728 KB |
Output is correct |
35 |
Correct |
159 ms |
4844 KB |
Output is correct |
36 |
Correct |
165 ms |
4856 KB |
Output is correct |
37 |
Correct |
171 ms |
4780 KB |
Output is correct |
38 |
Correct |
131 ms |
4076 KB |
Output is correct |
39 |
Correct |
132 ms |
4076 KB |
Output is correct |
40 |
Correct |
132 ms |
4084 KB |
Output is correct |
41 |
Correct |
129 ms |
4076 KB |
Output is correct |
42 |
Correct |
128 ms |
4076 KB |
Output is correct |
43 |
Correct |
129 ms |
4076 KB |
Output is correct |
44 |
Correct |
122 ms |
3952 KB |
Output is correct |
45 |
Correct |
129 ms |
4004 KB |
Output is correct |
46 |
Correct |
121 ms |
4076 KB |
Output is correct |
47 |
Correct |
614 ms |
16708 KB |
Output is correct |
48 |
Correct |
2538 ms |
44752 KB |
Output is correct |
49 |
Correct |
2629 ms |
47188 KB |
Output is correct |
50 |
Correct |
2671 ms |
47284 KB |
Output is correct |
51 |
Correct |
2857 ms |
47232 KB |
Output is correct |
52 |
Correct |
2624 ms |
47316 KB |
Output is correct |
53 |
Correct |
2655 ms |
47160 KB |
Output is correct |
54 |
Correct |
2388 ms |
47444 KB |
Output is correct |
55 |
Correct |
2523 ms |
47572 KB |
Output is correct |
56 |
Correct |
2571 ms |
47572 KB |
Output is correct |
57 |
Correct |
2497 ms |
47416 KB |
Output is correct |
58 |
Correct |
2450 ms |
47324 KB |
Output is correct |
59 |
Correct |
2212 ms |
46036 KB |
Output is correct |
60 |
Correct |
2195 ms |
46036 KB |
Output is correct |
61 |
Correct |
2198 ms |
46036 KB |
Output is correct |
62 |
Correct |
2237 ms |
45908 KB |
Output is correct |
63 |
Correct |
2110 ms |
45972 KB |
Output is correct |
64 |
Correct |
2134 ms |
46164 KB |
Output is correct |
65 |
Correct |
2192 ms |
45872 KB |
Output is correct |
66 |
Correct |
2009 ms |
45780 KB |
Output is correct |
67 |
Correct |
2070 ms |
45780 KB |
Output is correct |