#include <bits/stdc++.h>
const int N = 1e6 + 5;
struct node {
std::pair<int, int> x;
int y = rand();
int L = 0, R = 0;
int sz = 1;
int cost = -1e9;
} t[N];
int cur = 0;
void pull(int v) { t[v].sz = t[t[v].L].sz + t[t[v].R].sz + 1, t[v].cost = std::max({t[t[v].L].cost, t[v].x.second - t[t[v].L].sz, t[t[v].R].cost - t[t[v].L].sz - 1}); }
int merge(int v, int u) {
if (!v || !u) return v | u;
if (t[v].y > t[u].y) return t[v].R = merge(t[v].R, u), pull(v), v;
return pull(t[u].L = merge(v, t[u].L)), pull(u), u;
}
std::pair<int, int> split(int v, std::pair<int, int> x) {
if (!v) return {v, v};
if (t[v].x <= x) {
auto [a, b] = split(t[v].R, x);
return t[v].R = a, pull(v), std::pair{v, b};
}
auto [a, b] = split(t[v].L, x);
return t[v].L = b, pull(v), std::pair{a, v};
}
void add(int&v, std::pair<int, int> x) {
auto [a, b] = split(v, x);
t[++cur].x = x, pull(cur), v = merge(merge(a, cur), b);
}
void del(int&v, std::pair<int, int> x) {
auto [a, b] = split(v, x);
auto [y, z] = split(a, {x.first, x.second - 1});
v = merge(y, b);
}
std::vector<int> countScans(std::vector<int> A, std::vector<int> X, std::vector<int> V) {
t[0].sz = 0;
std::vector<int> ans(X.size());
int v = 0;
for (int i = 0; i < A.size(); ++i) add(v, {A[i], i});
for (int i = 0; i < X.size(); ++i) del(v, {A[X[i]], X[i]}), A[X[i]] = V[i], add(v, {A[X[i]], X[i]}), ans[i] = t[v].cost;
return ans;
}
#ifdef __APPLE__
#include <cstdio>
#include <cstdlib>
#include <vector>
int readInt() {
int i;
if (scanf("%d", &i) != 1) {
fprintf(stderr, "Error while reading input\n");
exit(1);
}
return i;
}
int main() {
int N, Q;
N = readInt();
Q = readInt();
std::vector<int> A(N);
for (int i = 0; i < N; i++)
A[i] = readInt();
std::vector<int> X(Q), V(Q);
for (int j = 0; j < Q; j++) {
X[j] = readInt();
V[j] = readInt();
}
std::vector<int> res = countScans(A, X, V);
for (int j = 0; j < int(res.size()); j++)
printf("%d\n", res[j]);
}
#endif
Compilation message
bubblesort2.cpp: In function 'std::vector<int> countScans(std::vector<int>, std::vector<int>, std::vector<int>)':
bubblesort2.cpp:47:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
47 | for (int i = 0; i < A.size(); ++i) add(v, {A[i], i});
| ~~^~~~~~~~~~
bubblesort2.cpp:48:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
48 | for (int i = 0; i < X.size(); ++i) del(v, {A[X[i]], X[i]}), A[X[i]] = V[i], add(v, {A[X[i]], X[i]}), ans[i] = t[v].cost;
| ~~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
27736 KB |
Output is correct |
2 |
Correct |
11 ms |
27740 KB |
Output is correct |
3 |
Correct |
13 ms |
27740 KB |
Output is correct |
4 |
Correct |
15 ms |
27736 KB |
Output is correct |
5 |
Correct |
13 ms |
27736 KB |
Output is correct |
6 |
Correct |
13 ms |
27736 KB |
Output is correct |
7 |
Correct |
15 ms |
27748 KB |
Output is correct |
8 |
Correct |
13 ms |
27740 KB |
Output is correct |
9 |
Correct |
13 ms |
27740 KB |
Output is correct |
10 |
Correct |
13 ms |
27740 KB |
Output is correct |
11 |
Correct |
13 ms |
27740 KB |
Output is correct |
12 |
Correct |
13 ms |
27892 KB |
Output is correct |
13 |
Correct |
13 ms |
27736 KB |
Output is correct |
14 |
Correct |
13 ms |
27740 KB |
Output is correct |
15 |
Correct |
13 ms |
27772 KB |
Output is correct |
16 |
Correct |
13 ms |
27740 KB |
Output is correct |
17 |
Correct |
13 ms |
27996 KB |
Output is correct |
18 |
Correct |
13 ms |
27736 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
27736 KB |
Output is correct |
2 |
Correct |
11 ms |
27740 KB |
Output is correct |
3 |
Correct |
13 ms |
27740 KB |
Output is correct |
4 |
Correct |
15 ms |
27736 KB |
Output is correct |
5 |
Correct |
13 ms |
27736 KB |
Output is correct |
6 |
Correct |
13 ms |
27736 KB |
Output is correct |
7 |
Correct |
15 ms |
27748 KB |
Output is correct |
8 |
Correct |
13 ms |
27740 KB |
Output is correct |
9 |
Correct |
13 ms |
27740 KB |
Output is correct |
10 |
Correct |
13 ms |
27740 KB |
Output is correct |
11 |
Correct |
13 ms |
27740 KB |
Output is correct |
12 |
Correct |
13 ms |
27892 KB |
Output is correct |
13 |
Correct |
13 ms |
27736 KB |
Output is correct |
14 |
Correct |
13 ms |
27740 KB |
Output is correct |
15 |
Correct |
13 ms |
27772 KB |
Output is correct |
16 |
Correct |
13 ms |
27740 KB |
Output is correct |
17 |
Correct |
13 ms |
27996 KB |
Output is correct |
18 |
Correct |
13 ms |
27736 KB |
Output is correct |
19 |
Correct |
24 ms |
27996 KB |
Output is correct |
20 |
Correct |
25 ms |
27996 KB |
Output is correct |
21 |
Correct |
25 ms |
28056 KB |
Output is correct |
22 |
Correct |
24 ms |
27996 KB |
Output is correct |
23 |
Correct |
23 ms |
27996 KB |
Output is correct |
24 |
Correct |
24 ms |
28020 KB |
Output is correct |
25 |
Correct |
23 ms |
28044 KB |
Output is correct |
26 |
Correct |
23 ms |
27996 KB |
Output is correct |
27 |
Correct |
24 ms |
27996 KB |
Output is correct |
28 |
Correct |
23 ms |
27996 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
29 ms |
27932 KB |
Output is correct |
2 |
Correct |
72 ms |
28508 KB |
Output is correct |
3 |
Correct |
121 ms |
29020 KB |
Output is correct |
4 |
Correct |
124 ms |
29440 KB |
Output is correct |
5 |
Correct |
119 ms |
29016 KB |
Output is correct |
6 |
Correct |
153 ms |
29196 KB |
Output is correct |
7 |
Correct |
122 ms |
29016 KB |
Output is correct |
8 |
Correct |
126 ms |
29012 KB |
Output is correct |
9 |
Correct |
123 ms |
29016 KB |
Output is correct |
10 |
Correct |
90 ms |
29200 KB |
Output is correct |
11 |
Correct |
89 ms |
29264 KB |
Output is correct |
12 |
Correct |
84 ms |
29016 KB |
Output is correct |
13 |
Correct |
76 ms |
29196 KB |
Output is correct |
14 |
Correct |
74 ms |
29188 KB |
Output is correct |
15 |
Correct |
80 ms |
29020 KB |
Output is correct |
16 |
Correct |
64 ms |
29060 KB |
Output is correct |
17 |
Correct |
62 ms |
29016 KB |
Output is correct |
18 |
Correct |
67 ms |
29020 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
27736 KB |
Output is correct |
2 |
Correct |
11 ms |
27740 KB |
Output is correct |
3 |
Correct |
13 ms |
27740 KB |
Output is correct |
4 |
Correct |
15 ms |
27736 KB |
Output is correct |
5 |
Correct |
13 ms |
27736 KB |
Output is correct |
6 |
Correct |
13 ms |
27736 KB |
Output is correct |
7 |
Correct |
15 ms |
27748 KB |
Output is correct |
8 |
Correct |
13 ms |
27740 KB |
Output is correct |
9 |
Correct |
13 ms |
27740 KB |
Output is correct |
10 |
Correct |
13 ms |
27740 KB |
Output is correct |
11 |
Correct |
13 ms |
27740 KB |
Output is correct |
12 |
Correct |
13 ms |
27892 KB |
Output is correct |
13 |
Correct |
13 ms |
27736 KB |
Output is correct |
14 |
Correct |
13 ms |
27740 KB |
Output is correct |
15 |
Correct |
13 ms |
27772 KB |
Output is correct |
16 |
Correct |
13 ms |
27740 KB |
Output is correct |
17 |
Correct |
13 ms |
27996 KB |
Output is correct |
18 |
Correct |
13 ms |
27736 KB |
Output is correct |
19 |
Correct |
24 ms |
27996 KB |
Output is correct |
20 |
Correct |
25 ms |
27996 KB |
Output is correct |
21 |
Correct |
25 ms |
28056 KB |
Output is correct |
22 |
Correct |
24 ms |
27996 KB |
Output is correct |
23 |
Correct |
23 ms |
27996 KB |
Output is correct |
24 |
Correct |
24 ms |
28020 KB |
Output is correct |
25 |
Correct |
23 ms |
28044 KB |
Output is correct |
26 |
Correct |
23 ms |
27996 KB |
Output is correct |
27 |
Correct |
24 ms |
27996 KB |
Output is correct |
28 |
Correct |
23 ms |
27996 KB |
Output is correct |
29 |
Correct |
29 ms |
27932 KB |
Output is correct |
30 |
Correct |
72 ms |
28508 KB |
Output is correct |
31 |
Correct |
121 ms |
29020 KB |
Output is correct |
32 |
Correct |
124 ms |
29440 KB |
Output is correct |
33 |
Correct |
119 ms |
29016 KB |
Output is correct |
34 |
Correct |
153 ms |
29196 KB |
Output is correct |
35 |
Correct |
122 ms |
29016 KB |
Output is correct |
36 |
Correct |
126 ms |
29012 KB |
Output is correct |
37 |
Correct |
123 ms |
29016 KB |
Output is correct |
38 |
Correct |
90 ms |
29200 KB |
Output is correct |
39 |
Correct |
89 ms |
29264 KB |
Output is correct |
40 |
Correct |
84 ms |
29016 KB |
Output is correct |
41 |
Correct |
76 ms |
29196 KB |
Output is correct |
42 |
Correct |
74 ms |
29188 KB |
Output is correct |
43 |
Correct |
80 ms |
29020 KB |
Output is correct |
44 |
Correct |
64 ms |
29060 KB |
Output is correct |
45 |
Correct |
62 ms |
29016 KB |
Output is correct |
46 |
Correct |
67 ms |
29020 KB |
Output is correct |
47 |
Correct |
409 ms |
31788 KB |
Output is correct |
48 |
Correct |
1831 ms |
40524 KB |
Output is correct |
49 |
Correct |
2118 ms |
41536 KB |
Output is correct |
50 |
Correct |
2066 ms |
41544 KB |
Output is correct |
51 |
Correct |
2134 ms |
41536 KB |
Output is correct |
52 |
Correct |
1908 ms |
41540 KB |
Output is correct |
53 |
Correct |
2158 ms |
41536 KB |
Output is correct |
54 |
Correct |
1837 ms |
41544 KB |
Output is correct |
55 |
Correct |
2048 ms |
41544 KB |
Output is correct |
56 |
Correct |
1764 ms |
41548 KB |
Output is correct |
57 |
Correct |
1968 ms |
41544 KB |
Output is correct |
58 |
Correct |
1748 ms |
41532 KB |
Output is correct |
59 |
Correct |
1742 ms |
41532 KB |
Output is correct |
60 |
Correct |
1565 ms |
41636 KB |
Output is correct |
61 |
Correct |
1776 ms |
41544 KB |
Output is correct |
62 |
Correct |
1581 ms |
41536 KB |
Output is correct |
63 |
Correct |
1703 ms |
41536 KB |
Output is correct |
64 |
Correct |
1649 ms |
41532 KB |
Output is correct |
65 |
Correct |
1579 ms |
41540 KB |
Output is correct |
66 |
Correct |
1446 ms |
41540 KB |
Output is correct |
67 |
Correct |
1574 ms |
41544 KB |
Output is correct |