#include "bubblesort2.h"
#include <algorithm>
#include <utility>
#include <vector>
using ll = long long;
ll seg[4000005], lazy[4000005];
inline void paint(int u, ll x)
{
seg[u] += x;
lazy[u] += x;
}
inline void push_down(int u)
{
if (lazy[u])
{
paint(u << 1, lazy[u]);
paint(u << 1 | 1, lazy[u]);
lazy[u] = 0;
}
}
inline void modify(int u, int l, int r, int L, int R, ll x)
{
if (L <= l && r <= R)
{
paint(u, x);
return;
}
push_down(u);
int m = l + r >> 1;
if (L <= m)
modify(u << 1, l, m, L, R, x);
if (m < R)
modify(u << 1 | 1, m + 1, r, L, R, x);
seg[u] = std::max(seg[u << 1], seg[u << 1 | 1]);
}
std::vector<int> countScans(std::vector<int> arr, std::vector<int> qx, std::vector<int> qv)
{
int n = arr.size(), q = qx.size();
std::vector<std::pair<int, int> > app;
for (int i = 0; i < n; i++)
app.emplace_back(arr[i], i);
for (int i = 0; i < q; i++)
app.emplace_back(qv[i], qx[i]);
std::sort(app.begin(), app.end());
app.erase(std::unique(app.begin(), app.end()), app.end());
auto get_idx = [&] (std::pair<int, int> x)
{
return std::lower_bound(app.begin(), app.end(), x) - app.begin();
};
auto update = [&] (int pos, int coef)
{
int idx = get_idx({arr[pos], pos});
modify(1, 0, app.size() - 1, idx, idx, pos * coef);
modify(1, 0, app.size() - 1, get_idx({arr[pos], -1}), app.size() - 1, -coef);
};
for (int i = 0; i < n; i++)
update(i, 1);
std::vector<int> ans(q);
for (int i = 0; i < q; i++)
{
int x = qx[i];
update(x, -1);
arr[x] = qv[i];
update(x, 1);
ans[i] = seg[1] + 1;
}
return ans;
}
Compilation message
bubblesort2.cpp: In function 'void modify(int, int, int, int, int, ll)':
bubblesort2.cpp:29:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
int m = l + r >> 1;
~~^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
376 KB |
Output is correct |
2 |
Correct |
3 ms |
504 KB |
Output is correct |
3 |
Correct |
5 ms |
632 KB |
Output is correct |
4 |
Correct |
5 ms |
504 KB |
Output is correct |
5 |
Correct |
5 ms |
632 KB |
Output is correct |
6 |
Correct |
5 ms |
508 KB |
Output is correct |
7 |
Correct |
6 ms |
632 KB |
Output is correct |
8 |
Correct |
6 ms |
632 KB |
Output is correct |
9 |
Correct |
6 ms |
632 KB |
Output is correct |
10 |
Correct |
5 ms |
508 KB |
Output is correct |
11 |
Correct |
5 ms |
504 KB |
Output is correct |
12 |
Correct |
5 ms |
504 KB |
Output is correct |
13 |
Correct |
5 ms |
632 KB |
Output is correct |
14 |
Correct |
5 ms |
632 KB |
Output is correct |
15 |
Correct |
5 ms |
632 KB |
Output is correct |
16 |
Correct |
5 ms |
504 KB |
Output is correct |
17 |
Correct |
5 ms |
504 KB |
Output is correct |
18 |
Correct |
5 ms |
632 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
376 KB |
Output is correct |
2 |
Correct |
3 ms |
504 KB |
Output is correct |
3 |
Correct |
5 ms |
632 KB |
Output is correct |
4 |
Correct |
5 ms |
504 KB |
Output is correct |
5 |
Correct |
5 ms |
632 KB |
Output is correct |
6 |
Correct |
5 ms |
508 KB |
Output is correct |
7 |
Correct |
6 ms |
632 KB |
Output is correct |
8 |
Correct |
6 ms |
632 KB |
Output is correct |
9 |
Correct |
6 ms |
632 KB |
Output is correct |
10 |
Correct |
5 ms |
508 KB |
Output is correct |
11 |
Correct |
5 ms |
504 KB |
Output is correct |
12 |
Correct |
5 ms |
504 KB |
Output is correct |
13 |
Correct |
5 ms |
632 KB |
Output is correct |
14 |
Correct |
5 ms |
632 KB |
Output is correct |
15 |
Correct |
5 ms |
632 KB |
Output is correct |
16 |
Correct |
5 ms |
504 KB |
Output is correct |
17 |
Correct |
5 ms |
504 KB |
Output is correct |
18 |
Correct |
5 ms |
632 KB |
Output is correct |
19 |
Correct |
17 ms |
1272 KB |
Output is correct |
20 |
Correct |
19 ms |
1272 KB |
Output is correct |
21 |
Correct |
18 ms |
1272 KB |
Output is correct |
22 |
Correct |
20 ms |
1272 KB |
Output is correct |
23 |
Correct |
17 ms |
1272 KB |
Output is correct |
24 |
Correct |
18 ms |
1276 KB |
Output is correct |
25 |
Correct |
17 ms |
1272 KB |
Output is correct |
26 |
Correct |
17 ms |
1212 KB |
Output is correct |
27 |
Correct |
17 ms |
1272 KB |
Output is correct |
28 |
Correct |
17 ms |
1272 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
27 ms |
2036 KB |
Output is correct |
2 |
Correct |
79 ms |
3744 KB |
Output is correct |
3 |
Correct |
155 ms |
6636 KB |
Output is correct |
4 |
Correct |
152 ms |
6640 KB |
Output is correct |
5 |
Correct |
151 ms |
6636 KB |
Output is correct |
6 |
Correct |
150 ms |
6636 KB |
Output is correct |
7 |
Correct |
141 ms |
6636 KB |
Output is correct |
8 |
Correct |
144 ms |
6592 KB |
Output is correct |
9 |
Correct |
139 ms |
6596 KB |
Output is correct |
10 |
Correct |
99 ms |
4460 KB |
Output is correct |
11 |
Correct |
98 ms |
4560 KB |
Output is correct |
12 |
Correct |
98 ms |
4564 KB |
Output is correct |
13 |
Correct |
99 ms |
4532 KB |
Output is correct |
14 |
Correct |
99 ms |
4588 KB |
Output is correct |
15 |
Correct |
94 ms |
4588 KB |
Output is correct |
16 |
Correct |
90 ms |
4588 KB |
Output is correct |
17 |
Correct |
90 ms |
4588 KB |
Output is correct |
18 |
Correct |
91 ms |
4588 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
376 KB |
Output is correct |
2 |
Correct |
3 ms |
504 KB |
Output is correct |
3 |
Correct |
5 ms |
632 KB |
Output is correct |
4 |
Correct |
5 ms |
504 KB |
Output is correct |
5 |
Correct |
5 ms |
632 KB |
Output is correct |
6 |
Correct |
5 ms |
508 KB |
Output is correct |
7 |
Correct |
6 ms |
632 KB |
Output is correct |
8 |
Correct |
6 ms |
632 KB |
Output is correct |
9 |
Correct |
6 ms |
632 KB |
Output is correct |
10 |
Correct |
5 ms |
508 KB |
Output is correct |
11 |
Correct |
5 ms |
504 KB |
Output is correct |
12 |
Correct |
5 ms |
504 KB |
Output is correct |
13 |
Correct |
5 ms |
632 KB |
Output is correct |
14 |
Correct |
5 ms |
632 KB |
Output is correct |
15 |
Correct |
5 ms |
632 KB |
Output is correct |
16 |
Correct |
5 ms |
504 KB |
Output is correct |
17 |
Correct |
5 ms |
504 KB |
Output is correct |
18 |
Correct |
5 ms |
632 KB |
Output is correct |
19 |
Correct |
17 ms |
1272 KB |
Output is correct |
20 |
Correct |
19 ms |
1272 KB |
Output is correct |
21 |
Correct |
18 ms |
1272 KB |
Output is correct |
22 |
Correct |
20 ms |
1272 KB |
Output is correct |
23 |
Correct |
17 ms |
1272 KB |
Output is correct |
24 |
Correct |
18 ms |
1276 KB |
Output is correct |
25 |
Correct |
17 ms |
1272 KB |
Output is correct |
26 |
Correct |
17 ms |
1212 KB |
Output is correct |
27 |
Correct |
17 ms |
1272 KB |
Output is correct |
28 |
Correct |
17 ms |
1272 KB |
Output is correct |
29 |
Correct |
27 ms |
2036 KB |
Output is correct |
30 |
Correct |
79 ms |
3744 KB |
Output is correct |
31 |
Correct |
155 ms |
6636 KB |
Output is correct |
32 |
Correct |
152 ms |
6640 KB |
Output is correct |
33 |
Correct |
151 ms |
6636 KB |
Output is correct |
34 |
Correct |
150 ms |
6636 KB |
Output is correct |
35 |
Correct |
141 ms |
6636 KB |
Output is correct |
36 |
Correct |
144 ms |
6592 KB |
Output is correct |
37 |
Correct |
139 ms |
6596 KB |
Output is correct |
38 |
Correct |
99 ms |
4460 KB |
Output is correct |
39 |
Correct |
98 ms |
4560 KB |
Output is correct |
40 |
Correct |
98 ms |
4564 KB |
Output is correct |
41 |
Correct |
99 ms |
4532 KB |
Output is correct |
42 |
Correct |
99 ms |
4588 KB |
Output is correct |
43 |
Correct |
94 ms |
4588 KB |
Output is correct |
44 |
Correct |
90 ms |
4588 KB |
Output is correct |
45 |
Correct |
90 ms |
4588 KB |
Output is correct |
46 |
Correct |
91 ms |
4588 KB |
Output is correct |
47 |
Correct |
540 ms |
23136 KB |
Output is correct |
48 |
Correct |
2302 ms |
53068 KB |
Output is correct |
49 |
Correct |
2434 ms |
67668 KB |
Output is correct |
50 |
Correct |
2617 ms |
67668 KB |
Output is correct |
51 |
Correct |
2694 ms |
67712 KB |
Output is correct |
52 |
Correct |
2678 ms |
67536 KB |
Output is correct |
53 |
Correct |
2751 ms |
67760 KB |
Output is correct |
54 |
Correct |
2494 ms |
67800 KB |
Output is correct |
55 |
Correct |
2499 ms |
67796 KB |
Output is correct |
56 |
Correct |
2096 ms |
67856 KB |
Output is correct |
57 |
Correct |
2540 ms |
67912 KB |
Output is correct |
58 |
Correct |
2248 ms |
67940 KB |
Output is correct |
59 |
Correct |
2016 ms |
66600 KB |
Output is correct |
60 |
Correct |
2067 ms |
66516 KB |
Output is correct |
61 |
Correct |
2057 ms |
66360 KB |
Output is correct |
62 |
Correct |
1836 ms |
66388 KB |
Output is correct |
63 |
Correct |
1967 ms |
66356 KB |
Output is correct |
64 |
Correct |
1983 ms |
66388 KB |
Output is correct |
65 |
Correct |
1828 ms |
66108 KB |
Output is correct |
66 |
Correct |
1821 ms |
66200 KB |
Output is correct |
67 |
Correct |
1735 ms |
66264 KB |
Output is correct |