#include <bits/stdc++.h>
#include "bubblesort2.h"
using namespace std;
#ifdef ngu
#include "debug.h"
#else
#define debug(...) 42
#endif
const int INF = int(1e8), N = int(1e6) + 5;
int n, m, q;
int s[4 * N], lz[4 * N];
void app(int id, int x) {
s[id] += x;
lz[id] += x;
}
void psh(int id) {
app(id * 2, lz[id]);
app(id * 2 + 1, lz[id]);
lz[id] = 0;
}
void change(int i, int v, int x) {
int id = 1, l = 1, r = m;
while (l ^ r) {
int md = (l + r) / 2;
if (lz[id]) {
psh(id);
}
id *= 2;
if (i <= md) {
app(id + 1, x);
r = md;
} else {
l = md + 1;
id += 1;
}
}
s[id] += v;
while (id > 1) {
id /= 2;
s[id] = max(s[id * 2], s[id * 2 + 1]);
}
}
std::vector<int> countScans(std::vector<int> A, std::vector<int> X, std::vector<int> V){
n = int(A.size());
q = int(X.size());
vector<int> res(q);
vector<pair<int, int>> values;
for (int i = 0; i < n; ++i) {
values.emplace_back(A[i], i);
}
for (int i = 0; i < q; ++i) {
values.emplace_back(V[i], X[i]);
}
sort(values.begin(), values.end());
values.erase(unique(values.begin(), values.end()), values.end());
auto upd = [&](int pos, int i, int x) {
int v = pos;
pos = lower_bound(values.begin(), values.end(), make_pair(pos, i)) - values.begin() + 1;
change(pos, x * (i + INF), -x);
};
m = int(values.size());
for (int i = 1; i < 4 * m; ++i) {
s[i] = -INF;
}
for (int i = 0; i < n; ++i) {
upd(A[i], i, 1);
}
for (int i = 0; i < q; ++i) {
upd(A[X[i]], X[i], -1);
upd(V[i], X[i], 1);
res[i] = s[1];
A[X[i]] = V[i];
}
return res;
}
Compilation message
bubblesort2.cpp: In lambda function:
bubblesort2.cpp:66:13: warning: unused variable 'v' [-Wunused-variable]
66 | int v = pos;
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
2 ms |
2396 KB |
Output is correct |
3 |
Correct |
3 ms |
2688 KB |
Output is correct |
4 |
Correct |
3 ms |
2652 KB |
Output is correct |
5 |
Correct |
2 ms |
2564 KB |
Output is correct |
6 |
Correct |
3 ms |
2648 KB |
Output is correct |
7 |
Correct |
3 ms |
2652 KB |
Output is correct |
8 |
Correct |
2 ms |
2652 KB |
Output is correct |
9 |
Correct |
2 ms |
2652 KB |
Output is correct |
10 |
Correct |
3 ms |
2648 KB |
Output is correct |
11 |
Correct |
2 ms |
2652 KB |
Output is correct |
12 |
Correct |
2 ms |
2652 KB |
Output is correct |
13 |
Correct |
3 ms |
2652 KB |
Output is correct |
14 |
Correct |
2 ms |
2652 KB |
Output is correct |
15 |
Correct |
2 ms |
2652 KB |
Output is correct |
16 |
Correct |
3 ms |
2652 KB |
Output is correct |
17 |
Correct |
3 ms |
2652 KB |
Output is correct |
18 |
Correct |
3 ms |
2652 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
2 ms |
2396 KB |
Output is correct |
3 |
Correct |
3 ms |
2688 KB |
Output is correct |
4 |
Correct |
3 ms |
2652 KB |
Output is correct |
5 |
Correct |
2 ms |
2564 KB |
Output is correct |
6 |
Correct |
3 ms |
2648 KB |
Output is correct |
7 |
Correct |
3 ms |
2652 KB |
Output is correct |
8 |
Correct |
2 ms |
2652 KB |
Output is correct |
9 |
Correct |
2 ms |
2652 KB |
Output is correct |
10 |
Correct |
3 ms |
2648 KB |
Output is correct |
11 |
Correct |
2 ms |
2652 KB |
Output is correct |
12 |
Correct |
2 ms |
2652 KB |
Output is correct |
13 |
Correct |
3 ms |
2652 KB |
Output is correct |
14 |
Correct |
2 ms |
2652 KB |
Output is correct |
15 |
Correct |
2 ms |
2652 KB |
Output is correct |
16 |
Correct |
3 ms |
2652 KB |
Output is correct |
17 |
Correct |
3 ms |
2652 KB |
Output is correct |
18 |
Correct |
3 ms |
2652 KB |
Output is correct |
19 |
Correct |
9 ms |
3164 KB |
Output is correct |
20 |
Correct |
9 ms |
3164 KB |
Output is correct |
21 |
Correct |
9 ms |
3228 KB |
Output is correct |
22 |
Correct |
11 ms |
3420 KB |
Output is correct |
23 |
Correct |
8 ms |
3160 KB |
Output is correct |
24 |
Correct |
8 ms |
3164 KB |
Output is correct |
25 |
Correct |
9 ms |
3164 KB |
Output is correct |
26 |
Correct |
8 ms |
3412 KB |
Output is correct |
27 |
Correct |
8 ms |
3164 KB |
Output is correct |
28 |
Correct |
8 ms |
3164 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
5344 KB |
Output is correct |
2 |
Correct |
36 ms |
8404 KB |
Output is correct |
3 |
Correct |
66 ms |
9416 KB |
Output is correct |
4 |
Correct |
73 ms |
9416 KB |
Output is correct |
5 |
Correct |
64 ms |
9424 KB |
Output is correct |
6 |
Correct |
63 ms |
9424 KB |
Output is correct |
7 |
Correct |
63 ms |
9468 KB |
Output is correct |
8 |
Correct |
62 ms |
9424 KB |
Output is correct |
9 |
Correct |
62 ms |
9424 KB |
Output is correct |
10 |
Correct |
50 ms |
7544 KB |
Output is correct |
11 |
Correct |
57 ms |
7640 KB |
Output is correct |
12 |
Correct |
49 ms |
7632 KB |
Output is correct |
13 |
Correct |
55 ms |
7624 KB |
Output is correct |
14 |
Correct |
48 ms |
7520 KB |
Output is correct |
15 |
Correct |
47 ms |
7624 KB |
Output is correct |
16 |
Correct |
44 ms |
7632 KB |
Output is correct |
17 |
Correct |
45 ms |
7632 KB |
Output is correct |
18 |
Correct |
49 ms |
7736 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
2 ms |
2396 KB |
Output is correct |
3 |
Correct |
3 ms |
2688 KB |
Output is correct |
4 |
Correct |
3 ms |
2652 KB |
Output is correct |
5 |
Correct |
2 ms |
2564 KB |
Output is correct |
6 |
Correct |
3 ms |
2648 KB |
Output is correct |
7 |
Correct |
3 ms |
2652 KB |
Output is correct |
8 |
Correct |
2 ms |
2652 KB |
Output is correct |
9 |
Correct |
2 ms |
2652 KB |
Output is correct |
10 |
Correct |
3 ms |
2648 KB |
Output is correct |
11 |
Correct |
2 ms |
2652 KB |
Output is correct |
12 |
Correct |
2 ms |
2652 KB |
Output is correct |
13 |
Correct |
3 ms |
2652 KB |
Output is correct |
14 |
Correct |
2 ms |
2652 KB |
Output is correct |
15 |
Correct |
2 ms |
2652 KB |
Output is correct |
16 |
Correct |
3 ms |
2652 KB |
Output is correct |
17 |
Correct |
3 ms |
2652 KB |
Output is correct |
18 |
Correct |
3 ms |
2652 KB |
Output is correct |
19 |
Correct |
9 ms |
3164 KB |
Output is correct |
20 |
Correct |
9 ms |
3164 KB |
Output is correct |
21 |
Correct |
9 ms |
3228 KB |
Output is correct |
22 |
Correct |
11 ms |
3420 KB |
Output is correct |
23 |
Correct |
8 ms |
3160 KB |
Output is correct |
24 |
Correct |
8 ms |
3164 KB |
Output is correct |
25 |
Correct |
9 ms |
3164 KB |
Output is correct |
26 |
Correct |
8 ms |
3412 KB |
Output is correct |
27 |
Correct |
8 ms |
3164 KB |
Output is correct |
28 |
Correct |
8 ms |
3164 KB |
Output is correct |
29 |
Correct |
12 ms |
5344 KB |
Output is correct |
30 |
Correct |
36 ms |
8404 KB |
Output is correct |
31 |
Correct |
66 ms |
9416 KB |
Output is correct |
32 |
Correct |
73 ms |
9416 KB |
Output is correct |
33 |
Correct |
64 ms |
9424 KB |
Output is correct |
34 |
Correct |
63 ms |
9424 KB |
Output is correct |
35 |
Correct |
63 ms |
9468 KB |
Output is correct |
36 |
Correct |
62 ms |
9424 KB |
Output is correct |
37 |
Correct |
62 ms |
9424 KB |
Output is correct |
38 |
Correct |
50 ms |
7544 KB |
Output is correct |
39 |
Correct |
57 ms |
7640 KB |
Output is correct |
40 |
Correct |
49 ms |
7632 KB |
Output is correct |
41 |
Correct |
55 ms |
7624 KB |
Output is correct |
42 |
Correct |
48 ms |
7520 KB |
Output is correct |
43 |
Correct |
47 ms |
7624 KB |
Output is correct |
44 |
Correct |
44 ms |
7632 KB |
Output is correct |
45 |
Correct |
45 ms |
7632 KB |
Output is correct |
46 |
Correct |
49 ms |
7736 KB |
Output is correct |
47 |
Correct |
240 ms |
21696 KB |
Output is correct |
48 |
Correct |
1077 ms |
57556 KB |
Output is correct |
49 |
Correct |
1203 ms |
60080 KB |
Output is correct |
50 |
Correct |
1135 ms |
60088 KB |
Output is correct |
51 |
Correct |
1226 ms |
60092 KB |
Output is correct |
52 |
Correct |
1189 ms |
60080 KB |
Output is correct |
53 |
Correct |
1140 ms |
60436 KB |
Output is correct |
54 |
Correct |
1062 ms |
60240 KB |
Output is correct |
55 |
Correct |
1083 ms |
60296 KB |
Output is correct |
56 |
Correct |
1008 ms |
60044 KB |
Output is correct |
57 |
Correct |
1092 ms |
60336 KB |
Output is correct |
58 |
Correct |
1016 ms |
60336 KB |
Output is correct |
59 |
Correct |
898 ms |
58544 KB |
Output is correct |
60 |
Correct |
928 ms |
58368 KB |
Output is correct |
61 |
Correct |
906 ms |
58548 KB |
Output is correct |
62 |
Correct |
892 ms |
55476 KB |
Output is correct |
63 |
Correct |
860 ms |
56244 KB |
Output is correct |
64 |
Correct |
879 ms |
56248 KB |
Output is correct |
65 |
Correct |
780 ms |
56496 KB |
Output is correct |
66 |
Correct |
820 ms |
56332 KB |
Output is correct |
67 |
Correct |
772 ms |
56320 KB |
Output is correct |