#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;
#define pb push_back
#define f first
#define s second
int N, Q, MX; pii tree[4000010]; vector<pii> allX; const int INF = 1000000000;
int getX(pii P) { return lower_bound(allX.begin(), allX.end(), P) - allX.begin() + 1; }
void pushdown(int x, int l, int r) {
tree[x].f += tree[x].s; if (l < r) { tree[2 * x].s += tree[x].s; tree[2 * x + 1].s += tree[x].s; } tree[x].s = 0;
}
void updRange(int x, int l, int r, int tl, int tr, int C) { int mid = (l + r) / 2;
pushdown(x, l, r); if (l > tr || r < tl) return ; if (tl <= l && r <= tr) { tree[x].s += C; return ; }
updRange(2 * x, l, mid, tl, tr, C); updRange(2 * x + 1, mid + 1, r, tl, tr, C);
pushdown(2 * x, l, mid); pushdown(2 * x + 1, mid + 1, r); tree[x].f = max(tree[2 * x].f, tree[2 * x + 1].f);
}
void INSERT(pii P) { int X = getX(P); updRange(1, 1, MX, X, X, INF + P.s); updRange(1, 1, MX, X + 1, MX, -1); }
void REMOVE(pii P) { int X = getX(P); updRange(1, 1, MX, X, X, -INF - P.s); updRange(1, 1, MX, X + 1, MX, 1); }
vector<int> countScans(vector<int> A, vector<int> X, vector<int> V) { int N = A.size(); int Q = X.size();
for (int i = 0; i < N; i++) allX.pb(pii {A[i], i}); for (int i = 0; i < Q; i++) allX.pb(pii {V[i], X[i]});
sort(allX.begin(), allX.end()); allX.resize(distance(allX.begin(), unique(allX.begin(), allX.end())));
MX = allX.size(); updRange(1, 1, MX, 1, MX, -INF);
for (int i = 0; i < N; i++) INSERT(pii {A[i], i});
vector<int> res; for (int i = 0; i < Q; i++) {
REMOVE(pii {A[X[i]], X[i]}); INSERT(pii {V[i], X[i]});
A[X[i]] = V[i]; res.pb(tree[1].f);
}
return res;
}
Compilation message
bubblesort2.cpp: In function 'std::vector<int> countScans(std::vector<int>, std::vector<int>, std::vector<int>)':
bubblesort2.cpp:30:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
30 | for (int i = 0; i < N; i++) allX.pb(pii {A[i], i}); for (int i = 0; i < Q; i++) allX.pb(pii {V[i], X[i]});
| ^~~
bubblesort2.cpp:30:57: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
30 | for (int i = 0; i < N; i++) allX.pb(pii {A[i], i}); for (int i = 0; i < Q; i++) allX.pb(pii {V[i], X[i]});
| ^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
364 KB |
Output is correct |
2 |
Correct |
3 ms |
364 KB |
Output is correct |
3 |
Correct |
7 ms |
492 KB |
Output is correct |
4 |
Correct |
7 ms |
492 KB |
Output is correct |
5 |
Correct |
7 ms |
492 KB |
Output is correct |
6 |
Correct |
7 ms |
492 KB |
Output is correct |
7 |
Correct |
7 ms |
492 KB |
Output is correct |
8 |
Correct |
7 ms |
492 KB |
Output is correct |
9 |
Correct |
7 ms |
492 KB |
Output is correct |
10 |
Correct |
7 ms |
492 KB |
Output is correct |
11 |
Correct |
7 ms |
492 KB |
Output is correct |
12 |
Correct |
7 ms |
492 KB |
Output is correct |
13 |
Correct |
8 ms |
492 KB |
Output is correct |
14 |
Correct |
7 ms |
492 KB |
Output is correct |
15 |
Correct |
7 ms |
492 KB |
Output is correct |
16 |
Correct |
6 ms |
492 KB |
Output is correct |
17 |
Correct |
6 ms |
492 KB |
Output is correct |
18 |
Correct |
6 ms |
492 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
364 KB |
Output is correct |
2 |
Correct |
3 ms |
364 KB |
Output is correct |
3 |
Correct |
7 ms |
492 KB |
Output is correct |
4 |
Correct |
7 ms |
492 KB |
Output is correct |
5 |
Correct |
7 ms |
492 KB |
Output is correct |
6 |
Correct |
7 ms |
492 KB |
Output is correct |
7 |
Correct |
7 ms |
492 KB |
Output is correct |
8 |
Correct |
7 ms |
492 KB |
Output is correct |
9 |
Correct |
7 ms |
492 KB |
Output is correct |
10 |
Correct |
7 ms |
492 KB |
Output is correct |
11 |
Correct |
7 ms |
492 KB |
Output is correct |
12 |
Correct |
7 ms |
492 KB |
Output is correct |
13 |
Correct |
8 ms |
492 KB |
Output is correct |
14 |
Correct |
7 ms |
492 KB |
Output is correct |
15 |
Correct |
7 ms |
492 KB |
Output is correct |
16 |
Correct |
6 ms |
492 KB |
Output is correct |
17 |
Correct |
6 ms |
492 KB |
Output is correct |
18 |
Correct |
6 ms |
492 KB |
Output is correct |
19 |
Correct |
25 ms |
1004 KB |
Output is correct |
20 |
Correct |
28 ms |
1004 KB |
Output is correct |
21 |
Correct |
27 ms |
1004 KB |
Output is correct |
22 |
Correct |
28 ms |
1004 KB |
Output is correct |
23 |
Correct |
27 ms |
1004 KB |
Output is correct |
24 |
Correct |
29 ms |
1004 KB |
Output is correct |
25 |
Correct |
27 ms |
1224 KB |
Output is correct |
26 |
Correct |
26 ms |
1004 KB |
Output is correct |
27 |
Correct |
26 ms |
1004 KB |
Output is correct |
28 |
Correct |
27 ms |
1004 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
40 ms |
1512 KB |
Output is correct |
2 |
Correct |
118 ms |
2788 KB |
Output is correct |
3 |
Correct |
212 ms |
4832 KB |
Output is correct |
4 |
Correct |
215 ms |
4860 KB |
Output is correct |
5 |
Correct |
215 ms |
4832 KB |
Output is correct |
6 |
Correct |
212 ms |
4832 KB |
Output is correct |
7 |
Correct |
212 ms |
4832 KB |
Output is correct |
8 |
Correct |
214 ms |
4852 KB |
Output is correct |
9 |
Correct |
211 ms |
4824 KB |
Output is correct |
10 |
Correct |
176 ms |
3808 KB |
Output is correct |
11 |
Correct |
178 ms |
3808 KB |
Output is correct |
12 |
Correct |
183 ms |
3808 KB |
Output is correct |
13 |
Correct |
175 ms |
3780 KB |
Output is correct |
14 |
Correct |
180 ms |
3808 KB |
Output is correct |
15 |
Correct |
171 ms |
3808 KB |
Output is correct |
16 |
Correct |
168 ms |
3936 KB |
Output is correct |
17 |
Correct |
166 ms |
3808 KB |
Output is correct |
18 |
Correct |
170 ms |
3808 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
364 KB |
Output is correct |
2 |
Correct |
3 ms |
364 KB |
Output is correct |
3 |
Correct |
7 ms |
492 KB |
Output is correct |
4 |
Correct |
7 ms |
492 KB |
Output is correct |
5 |
Correct |
7 ms |
492 KB |
Output is correct |
6 |
Correct |
7 ms |
492 KB |
Output is correct |
7 |
Correct |
7 ms |
492 KB |
Output is correct |
8 |
Correct |
7 ms |
492 KB |
Output is correct |
9 |
Correct |
7 ms |
492 KB |
Output is correct |
10 |
Correct |
7 ms |
492 KB |
Output is correct |
11 |
Correct |
7 ms |
492 KB |
Output is correct |
12 |
Correct |
7 ms |
492 KB |
Output is correct |
13 |
Correct |
8 ms |
492 KB |
Output is correct |
14 |
Correct |
7 ms |
492 KB |
Output is correct |
15 |
Correct |
7 ms |
492 KB |
Output is correct |
16 |
Correct |
6 ms |
492 KB |
Output is correct |
17 |
Correct |
6 ms |
492 KB |
Output is correct |
18 |
Correct |
6 ms |
492 KB |
Output is correct |
19 |
Correct |
25 ms |
1004 KB |
Output is correct |
20 |
Correct |
28 ms |
1004 KB |
Output is correct |
21 |
Correct |
27 ms |
1004 KB |
Output is correct |
22 |
Correct |
28 ms |
1004 KB |
Output is correct |
23 |
Correct |
27 ms |
1004 KB |
Output is correct |
24 |
Correct |
29 ms |
1004 KB |
Output is correct |
25 |
Correct |
27 ms |
1224 KB |
Output is correct |
26 |
Correct |
26 ms |
1004 KB |
Output is correct |
27 |
Correct |
26 ms |
1004 KB |
Output is correct |
28 |
Correct |
27 ms |
1004 KB |
Output is correct |
29 |
Correct |
40 ms |
1512 KB |
Output is correct |
30 |
Correct |
118 ms |
2788 KB |
Output is correct |
31 |
Correct |
212 ms |
4832 KB |
Output is correct |
32 |
Correct |
215 ms |
4860 KB |
Output is correct |
33 |
Correct |
215 ms |
4832 KB |
Output is correct |
34 |
Correct |
212 ms |
4832 KB |
Output is correct |
35 |
Correct |
212 ms |
4832 KB |
Output is correct |
36 |
Correct |
214 ms |
4852 KB |
Output is correct |
37 |
Correct |
211 ms |
4824 KB |
Output is correct |
38 |
Correct |
176 ms |
3808 KB |
Output is correct |
39 |
Correct |
178 ms |
3808 KB |
Output is correct |
40 |
Correct |
183 ms |
3808 KB |
Output is correct |
41 |
Correct |
175 ms |
3780 KB |
Output is correct |
42 |
Correct |
180 ms |
3808 KB |
Output is correct |
43 |
Correct |
171 ms |
3808 KB |
Output is correct |
44 |
Correct |
168 ms |
3936 KB |
Output is correct |
45 |
Correct |
166 ms |
3808 KB |
Output is correct |
46 |
Correct |
170 ms |
3808 KB |
Output is correct |
47 |
Correct |
788 ms |
15980 KB |
Output is correct |
48 |
Correct |
3225 ms |
38844 KB |
Output is correct |
49 |
Correct |
3453 ms |
53432 KB |
Output is correct |
50 |
Correct |
3447 ms |
53192 KB |
Output is correct |
51 |
Correct |
3444 ms |
53448 KB |
Output is correct |
52 |
Correct |
3478 ms |
53320 KB |
Output is correct |
53 |
Correct |
3463 ms |
53244 KB |
Output is correct |
54 |
Correct |
3161 ms |
53496 KB |
Output is correct |
55 |
Correct |
3322 ms |
53448 KB |
Output is correct |
56 |
Correct |
3185 ms |
53716 KB |
Output is correct |
57 |
Correct |
3278 ms |
53748 KB |
Output is correct |
58 |
Correct |
3126 ms |
53372 KB |
Output is correct |
59 |
Correct |
2943 ms |
52184 KB |
Output is correct |
60 |
Correct |
2923 ms |
52056 KB |
Output is correct |
61 |
Correct |
2920 ms |
52264 KB |
Output is correct |
62 |
Correct |
2818 ms |
52168 KB |
Output is correct |
63 |
Correct |
2839 ms |
52040 KB |
Output is correct |
64 |
Correct |
2802 ms |
52080 KB |
Output is correct |
65 |
Correct |
2663 ms |
51912 KB |
Output is correct |
66 |
Correct |
2640 ms |
52040 KB |
Output is correct |
67 |
Correct |
2647 ms |
52064 KB |
Output is correct |