#include "bubblesort2.h"
#include <bits/stdc++.h>
#define pii pair<int, int>
#define x first
#define y second
using namespace std;
#define var int p = 1, int l = 0, int r = coord.size() - 1
#define mid ((l + r) >> 1)
#define lb p << 1, l, mid
#define rb p << 1 | 1, mid + 1, r
const int N = 1 << 20;
int n, q;
int t[N << 1], lz[N << 1];
vector<pii> coord;
int get(pii x) { return lower_bound(coord.begin(), coord.end(), x) - coord.begin(); }
void push(var) {
if(lz[p]) {
t[p] += lz[p];
if(l != r) lz[p << 1] += lz[p], lz[p << 1 | 1] += lz[p];
lz[p] = 0;
}
}
void update(int x, int y, int k, var) {
push(p, l, r);
if(x > r || l > y) return;
if(x <= l && r <= y) {
lz[p] += k, push(p, l, r);
return;
}
update(x, y, k, lb), update(x, y, k, rb);
t[p] = max(t[p << 1], t[p << 1 | 1]);
}
vector<int> countScans(vector<int> A, vector<int> X, vector<int> V) {
n = A.size(), q = X.size();
for(int i = 0; i < n; i++) coord.emplace_back(A[i], i);
for(int i = 0; i < q; i++) coord.emplace_back(V[i], X[i]);
sort(coord.begin(), coord.end());
coord.resize(unique(coord.begin(), coord.end()) - coord.begin());
function<void(int, int)> add = [&](int i, int coef) {
int idx1 = get(pii(A[i], i));
update(idx1, idx1, (i + 1) * coef);
int idx2 = get(pii(A[i], -1));
update(idx2, coord.size() - 1, -coef);
};
vector<int> ans;
for(int i = 0; i < n; i++) add(i, 1);
for(int i = 0; i < q; i++) {
add(X[i], -1);
A[X[i]] = V[i];
add(X[i], 1);
ans.emplace_back(t[1]);
}
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
384 KB |
Output is correct |
2 |
Correct |
7 ms |
384 KB |
Output is correct |
3 |
Correct |
10 ms |
512 KB |
Output is correct |
4 |
Correct |
10 ms |
512 KB |
Output is correct |
5 |
Correct |
10 ms |
512 KB |
Output is correct |
6 |
Correct |
10 ms |
512 KB |
Output is correct |
7 |
Correct |
9 ms |
512 KB |
Output is correct |
8 |
Correct |
10 ms |
512 KB |
Output is correct |
9 |
Correct |
10 ms |
512 KB |
Output is correct |
10 |
Correct |
10 ms |
512 KB |
Output is correct |
11 |
Correct |
9 ms |
512 KB |
Output is correct |
12 |
Correct |
9 ms |
512 KB |
Output is correct |
13 |
Correct |
9 ms |
512 KB |
Output is correct |
14 |
Correct |
9 ms |
512 KB |
Output is correct |
15 |
Correct |
9 ms |
512 KB |
Output is correct |
16 |
Correct |
9 ms |
512 KB |
Output is correct |
17 |
Correct |
9 ms |
512 KB |
Output is correct |
18 |
Correct |
9 ms |
512 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
384 KB |
Output is correct |
2 |
Correct |
7 ms |
384 KB |
Output is correct |
3 |
Correct |
10 ms |
512 KB |
Output is correct |
4 |
Correct |
10 ms |
512 KB |
Output is correct |
5 |
Correct |
10 ms |
512 KB |
Output is correct |
6 |
Correct |
10 ms |
512 KB |
Output is correct |
7 |
Correct |
9 ms |
512 KB |
Output is correct |
8 |
Correct |
10 ms |
512 KB |
Output is correct |
9 |
Correct |
10 ms |
512 KB |
Output is correct |
10 |
Correct |
10 ms |
512 KB |
Output is correct |
11 |
Correct |
9 ms |
512 KB |
Output is correct |
12 |
Correct |
9 ms |
512 KB |
Output is correct |
13 |
Correct |
9 ms |
512 KB |
Output is correct |
14 |
Correct |
9 ms |
512 KB |
Output is correct |
15 |
Correct |
9 ms |
512 KB |
Output is correct |
16 |
Correct |
9 ms |
512 KB |
Output is correct |
17 |
Correct |
9 ms |
512 KB |
Output is correct |
18 |
Correct |
9 ms |
512 KB |
Output is correct |
19 |
Correct |
26 ms |
1024 KB |
Output is correct |
20 |
Correct |
29 ms |
1024 KB |
Output is correct |
21 |
Correct |
28 ms |
1024 KB |
Output is correct |
22 |
Correct |
28 ms |
1024 KB |
Output is correct |
23 |
Correct |
27 ms |
1024 KB |
Output is correct |
24 |
Correct |
26 ms |
1152 KB |
Output is correct |
25 |
Correct |
25 ms |
1024 KB |
Output is correct |
26 |
Correct |
26 ms |
1024 KB |
Output is correct |
27 |
Correct |
24 ms |
1024 KB |
Output is correct |
28 |
Correct |
26 ms |
1152 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
35 ms |
1532 KB |
Output is correct |
2 |
Correct |
108 ms |
2776 KB |
Output is correct |
3 |
Correct |
180 ms |
4844 KB |
Output is correct |
4 |
Correct |
189 ms |
4844 KB |
Output is correct |
5 |
Correct |
179 ms |
4844 KB |
Output is correct |
6 |
Correct |
180 ms |
4848 KB |
Output is correct |
7 |
Correct |
180 ms |
4844 KB |
Output is correct |
8 |
Correct |
179 ms |
4844 KB |
Output is correct |
9 |
Correct |
180 ms |
4812 KB |
Output is correct |
10 |
Correct |
143 ms |
3820 KB |
Output is correct |
11 |
Correct |
134 ms |
3824 KB |
Output is correct |
12 |
Correct |
145 ms |
3820 KB |
Output is correct |
13 |
Correct |
144 ms |
3820 KB |
Output is correct |
14 |
Correct |
142 ms |
3820 KB |
Output is correct |
15 |
Correct |
140 ms |
3820 KB |
Output is correct |
16 |
Correct |
131 ms |
3820 KB |
Output is correct |
17 |
Correct |
135 ms |
3820 KB |
Output is correct |
18 |
Correct |
143 ms |
3768 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
384 KB |
Output is correct |
2 |
Correct |
7 ms |
384 KB |
Output is correct |
3 |
Correct |
10 ms |
512 KB |
Output is correct |
4 |
Correct |
10 ms |
512 KB |
Output is correct |
5 |
Correct |
10 ms |
512 KB |
Output is correct |
6 |
Correct |
10 ms |
512 KB |
Output is correct |
7 |
Correct |
9 ms |
512 KB |
Output is correct |
8 |
Correct |
10 ms |
512 KB |
Output is correct |
9 |
Correct |
10 ms |
512 KB |
Output is correct |
10 |
Correct |
10 ms |
512 KB |
Output is correct |
11 |
Correct |
9 ms |
512 KB |
Output is correct |
12 |
Correct |
9 ms |
512 KB |
Output is correct |
13 |
Correct |
9 ms |
512 KB |
Output is correct |
14 |
Correct |
9 ms |
512 KB |
Output is correct |
15 |
Correct |
9 ms |
512 KB |
Output is correct |
16 |
Correct |
9 ms |
512 KB |
Output is correct |
17 |
Correct |
9 ms |
512 KB |
Output is correct |
18 |
Correct |
9 ms |
512 KB |
Output is correct |
19 |
Correct |
26 ms |
1024 KB |
Output is correct |
20 |
Correct |
29 ms |
1024 KB |
Output is correct |
21 |
Correct |
28 ms |
1024 KB |
Output is correct |
22 |
Correct |
28 ms |
1024 KB |
Output is correct |
23 |
Correct |
27 ms |
1024 KB |
Output is correct |
24 |
Correct |
26 ms |
1152 KB |
Output is correct |
25 |
Correct |
25 ms |
1024 KB |
Output is correct |
26 |
Correct |
26 ms |
1024 KB |
Output is correct |
27 |
Correct |
24 ms |
1024 KB |
Output is correct |
28 |
Correct |
26 ms |
1152 KB |
Output is correct |
29 |
Correct |
35 ms |
1532 KB |
Output is correct |
30 |
Correct |
108 ms |
2776 KB |
Output is correct |
31 |
Correct |
180 ms |
4844 KB |
Output is correct |
32 |
Correct |
189 ms |
4844 KB |
Output is correct |
33 |
Correct |
179 ms |
4844 KB |
Output is correct |
34 |
Correct |
180 ms |
4848 KB |
Output is correct |
35 |
Correct |
180 ms |
4844 KB |
Output is correct |
36 |
Correct |
179 ms |
4844 KB |
Output is correct |
37 |
Correct |
180 ms |
4812 KB |
Output is correct |
38 |
Correct |
143 ms |
3820 KB |
Output is correct |
39 |
Correct |
134 ms |
3824 KB |
Output is correct |
40 |
Correct |
145 ms |
3820 KB |
Output is correct |
41 |
Correct |
144 ms |
3820 KB |
Output is correct |
42 |
Correct |
142 ms |
3820 KB |
Output is correct |
43 |
Correct |
140 ms |
3820 KB |
Output is correct |
44 |
Correct |
131 ms |
3820 KB |
Output is correct |
45 |
Correct |
135 ms |
3820 KB |
Output is correct |
46 |
Correct |
143 ms |
3768 KB |
Output is correct |
47 |
Correct |
662 ms |
15868 KB |
Output is correct |
48 |
Correct |
2745 ms |
38904 KB |
Output is correct |
49 |
Correct |
3050 ms |
53456 KB |
Output is correct |
50 |
Correct |
3075 ms |
53500 KB |
Output is correct |
51 |
Correct |
2990 ms |
53280 KB |
Output is correct |
52 |
Correct |
3010 ms |
53332 KB |
Output is correct |
53 |
Correct |
3048 ms |
53384 KB |
Output is correct |
54 |
Correct |
2732 ms |
53352 KB |
Output is correct |
55 |
Correct |
2925 ms |
53460 KB |
Output is correct |
56 |
Correct |
2656 ms |
53348 KB |
Output is correct |
57 |
Correct |
2805 ms |
53416 KB |
Output is correct |
58 |
Correct |
2707 ms |
53476 KB |
Output is correct |
59 |
Correct |
2449 ms |
52180 KB |
Output is correct |
60 |
Correct |
2491 ms |
52052 KB |
Output is correct |
61 |
Correct |
2347 ms |
52212 KB |
Output is correct |
62 |
Correct |
2385 ms |
51972 KB |
Output is correct |
63 |
Correct |
2228 ms |
52108 KB |
Output is correct |
64 |
Correct |
2207 ms |
51956 KB |
Output is correct |
65 |
Correct |
2125 ms |
51756 KB |
Output is correct |
66 |
Correct |
2025 ms |
51864 KB |
Output is correct |
67 |
Correct |
2033 ms |
51928 KB |
Output is correct |