#include <bits/stdc++.h>
using namespace std;
const int N = 200005;
struct segment_tree {
int mx[4 * N];
segment_tree() {
memset(mx, -0x3f, sizeof(mx));
}
void upd(int id, int tl, int tr, int pos, int val) {
if (tl == tr) {
mx[id] = val;
return;
}
int tm = tl + tr >> 1;
if (pos <= tm) {
upd(id << 1, tl, tm, pos, val);
} else if (tm + 1 <= pos) {
upd(id << 1 | 1, tm + 1, tr, pos, val);
}
mx[id] = max(mx[id << 1], mx[id << 1 | 1]);
}
};
int n;
int a[N], b[N];
int c[N], ans[N];
segment_tree st;
set<pair<int, int>> s;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n;
for (int i = 1; i <= n + 1; i++) {
cin >> a[i];
c[i] = a[i];
}
for (int i = 1; i <= n; i++) {
cin >> b[i];
}
sort(b + 1, b + n + 1);
sort(a + 1, a + n + 2);
for (int i = 1; i <= n + 1; i++) {
s.insert({a[i], i});
}
for (int i = 1; i <= n; i++) {
st.upd(1, 1, n, i, a[i + 1] - b[i]);
}
ans[1] = max(0, st.mx[1]);
for (int i = 2; i <= n + 1; i++) {
st.upd(1, 1, n, i - 1, a[i - 1] - b[i - 1]);
ans[i] = max(0, st.mx[1]);
}
for (int i = 1; i <= n + 1; i++) {
auto it = s.lower_bound({c[i], -1});
cout << ans[it->second] << ' ';
s.erase(it);
}
return 0;
}
Compilation message
ho_t1.cpp: In member function 'void segment_tree::upd(int, int, int, int, int)':
ho_t1.cpp:19:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
19 | int tm = tl + tr >> 1;
| ~~~^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
3412 KB |
Output is correct |
2 |
Correct |
1 ms |
3412 KB |
Output is correct |
3 |
Correct |
1 ms |
3412 KB |
Output is correct |
4 |
Correct |
1 ms |
3412 KB |
Output is correct |
5 |
Correct |
1 ms |
3412 KB |
Output is correct |
6 |
Correct |
2 ms |
3412 KB |
Output is correct |
7 |
Correct |
1 ms |
3412 KB |
Output is correct |
8 |
Correct |
1 ms |
3412 KB |
Output is correct |
9 |
Correct |
1 ms |
3412 KB |
Output is correct |
10 |
Correct |
1 ms |
3412 KB |
Output is correct |
11 |
Correct |
1 ms |
3412 KB |
Output is correct |
12 |
Correct |
1 ms |
3428 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
3412 KB |
Output is correct |
2 |
Correct |
1 ms |
3412 KB |
Output is correct |
3 |
Correct |
1 ms |
3412 KB |
Output is correct |
4 |
Correct |
1 ms |
3412 KB |
Output is correct |
5 |
Correct |
1 ms |
3412 KB |
Output is correct |
6 |
Correct |
2 ms |
3412 KB |
Output is correct |
7 |
Correct |
1 ms |
3412 KB |
Output is correct |
8 |
Correct |
1 ms |
3412 KB |
Output is correct |
9 |
Correct |
1 ms |
3412 KB |
Output is correct |
10 |
Correct |
1 ms |
3412 KB |
Output is correct |
11 |
Correct |
1 ms |
3412 KB |
Output is correct |
12 |
Correct |
1 ms |
3428 KB |
Output is correct |
13 |
Correct |
1 ms |
3412 KB |
Output is correct |
14 |
Correct |
2 ms |
3540 KB |
Output is correct |
15 |
Correct |
2 ms |
3540 KB |
Output is correct |
16 |
Correct |
1 ms |
3412 KB |
Output is correct |
17 |
Correct |
4 ms |
3540 KB |
Output is correct |
18 |
Correct |
2 ms |
3540 KB |
Output is correct |
19 |
Correct |
3 ms |
3576 KB |
Output is correct |
20 |
Correct |
2 ms |
3540 KB |
Output is correct |
21 |
Correct |
2 ms |
3524 KB |
Output is correct |
22 |
Correct |
2 ms |
3540 KB |
Output is correct |
23 |
Correct |
3 ms |
3540 KB |
Output is correct |
24 |
Correct |
2 ms |
3540 KB |
Output is correct |
25 |
Correct |
2 ms |
3540 KB |
Output is correct |
26 |
Correct |
2 ms |
3540 KB |
Output is correct |
27 |
Correct |
2 ms |
3540 KB |
Output is correct |
28 |
Correct |
2 ms |
3540 KB |
Output is correct |
29 |
Correct |
2 ms |
3540 KB |
Output is correct |
30 |
Correct |
2 ms |
3540 KB |
Output is correct |
31 |
Correct |
2 ms |
3540 KB |
Output is correct |
32 |
Correct |
3 ms |
3540 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
3412 KB |
Output is correct |
2 |
Correct |
1 ms |
3412 KB |
Output is correct |
3 |
Correct |
1 ms |
3412 KB |
Output is correct |
4 |
Correct |
1 ms |
3412 KB |
Output is correct |
5 |
Correct |
1 ms |
3412 KB |
Output is correct |
6 |
Correct |
2 ms |
3412 KB |
Output is correct |
7 |
Correct |
1 ms |
3412 KB |
Output is correct |
8 |
Correct |
1 ms |
3412 KB |
Output is correct |
9 |
Correct |
1 ms |
3412 KB |
Output is correct |
10 |
Correct |
1 ms |
3412 KB |
Output is correct |
11 |
Correct |
1 ms |
3412 KB |
Output is correct |
12 |
Correct |
1 ms |
3428 KB |
Output is correct |
13 |
Correct |
1 ms |
3412 KB |
Output is correct |
14 |
Correct |
2 ms |
3540 KB |
Output is correct |
15 |
Correct |
2 ms |
3540 KB |
Output is correct |
16 |
Correct |
1 ms |
3412 KB |
Output is correct |
17 |
Correct |
4 ms |
3540 KB |
Output is correct |
18 |
Correct |
2 ms |
3540 KB |
Output is correct |
19 |
Correct |
3 ms |
3576 KB |
Output is correct |
20 |
Correct |
2 ms |
3540 KB |
Output is correct |
21 |
Correct |
2 ms |
3524 KB |
Output is correct |
22 |
Correct |
2 ms |
3540 KB |
Output is correct |
23 |
Correct |
3 ms |
3540 KB |
Output is correct |
24 |
Correct |
2 ms |
3540 KB |
Output is correct |
25 |
Correct |
2 ms |
3540 KB |
Output is correct |
26 |
Correct |
2 ms |
3540 KB |
Output is correct |
27 |
Correct |
2 ms |
3540 KB |
Output is correct |
28 |
Correct |
2 ms |
3540 KB |
Output is correct |
29 |
Correct |
2 ms |
3540 KB |
Output is correct |
30 |
Correct |
2 ms |
3540 KB |
Output is correct |
31 |
Correct |
2 ms |
3540 KB |
Output is correct |
32 |
Correct |
3 ms |
3540 KB |
Output is correct |
33 |
Correct |
188 ms |
16836 KB |
Output is correct |
34 |
Correct |
210 ms |
17376 KB |
Output is correct |
35 |
Correct |
168 ms |
16996 KB |
Output is correct |
36 |
Correct |
175 ms |
17432 KB |
Output is correct |
37 |
Correct |
188 ms |
17816 KB |
Output is correct |
38 |
Correct |
177 ms |
17740 KB |
Output is correct |
39 |
Correct |
202 ms |
16772 KB |
Output is correct |
40 |
Correct |
199 ms |
16684 KB |
Output is correct |
41 |
Correct |
191 ms |
16848 KB |
Output is correct |
42 |
Correct |
196 ms |
16752 KB |
Output is correct |
43 |
Correct |
209 ms |
16628 KB |
Output is correct |
44 |
Correct |
191 ms |
16184 KB |
Output is correct |
45 |
Correct |
196 ms |
16380 KB |
Output is correct |
46 |
Correct |
170 ms |
16172 KB |
Output is correct |
47 |
Correct |
138 ms |
16460 KB |
Output is correct |
48 |
Correct |
148 ms |
16480 KB |
Output is correct |
49 |
Correct |
193 ms |
17024 KB |
Output is correct |
50 |
Correct |
188 ms |
17052 KB |
Output is correct |
51 |
Correct |
182 ms |
17020 KB |
Output is correct |
52 |
Correct |
181 ms |
17052 KB |
Output is correct |
53 |
Correct |
179 ms |
17124 KB |
Output is correct |