#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;
| ~~~^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 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 |
2 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 |
2 ms |
3412 KB |
Output is correct |
8 |
Correct |
1 ms |
3408 KB |
Output is correct |
9 |
Correct |
2 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 |
3412 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 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 |
2 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 |
2 ms |
3412 KB |
Output is correct |
8 |
Correct |
1 ms |
3408 KB |
Output is correct |
9 |
Correct |
2 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 |
3412 KB |
Output is correct |
13 |
Correct |
2 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 |
2 ms |
3540 KB |
Output is correct |
18 |
Correct |
2 ms |
3540 KB |
Output is correct |
19 |
Correct |
2 ms |
3540 KB |
Output is correct |
20 |
Correct |
2 ms |
3540 KB |
Output is correct |
21 |
Correct |
2 ms |
3540 KB |
Output is correct |
22 |
Correct |
2 ms |
3540 KB |
Output is correct |
23 |
Correct |
2 ms |
3540 KB |
Output is correct |
24 |
Correct |
3 ms |
3540 KB |
Output is correct |
25 |
Correct |
3 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 |
3 ms |
3540 KB |
Output is correct |
32 |
Correct |
2 ms |
3540 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 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 |
2 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 |
2 ms |
3412 KB |
Output is correct |
8 |
Correct |
1 ms |
3408 KB |
Output is correct |
9 |
Correct |
2 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 |
3412 KB |
Output is correct |
13 |
Correct |
2 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 |
2 ms |
3540 KB |
Output is correct |
18 |
Correct |
2 ms |
3540 KB |
Output is correct |
19 |
Correct |
2 ms |
3540 KB |
Output is correct |
20 |
Correct |
2 ms |
3540 KB |
Output is correct |
21 |
Correct |
2 ms |
3540 KB |
Output is correct |
22 |
Correct |
2 ms |
3540 KB |
Output is correct |
23 |
Correct |
2 ms |
3540 KB |
Output is correct |
24 |
Correct |
3 ms |
3540 KB |
Output is correct |
25 |
Correct |
3 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 |
3 ms |
3540 KB |
Output is correct |
32 |
Correct |
2 ms |
3540 KB |
Output is correct |
33 |
Correct |
175 ms |
16848 KB |
Output is correct |
34 |
Correct |
185 ms |
20852 KB |
Output is correct |
35 |
Correct |
171 ms |
20364 KB |
Output is correct |
36 |
Correct |
180 ms |
21192 KB |
Output is correct |
37 |
Correct |
186 ms |
21568 KB |
Output is correct |
38 |
Correct |
174 ms |
21500 KB |
Output is correct |
39 |
Correct |
192 ms |
20592 KB |
Output is correct |
40 |
Correct |
181 ms |
20424 KB |
Output is correct |
41 |
Correct |
181 ms |
20576 KB |
Output is correct |
42 |
Correct |
171 ms |
20640 KB |
Output is correct |
43 |
Correct |
169 ms |
20432 KB |
Output is correct |
44 |
Correct |
170 ms |
19848 KB |
Output is correct |
45 |
Correct |
185 ms |
20104 KB |
Output is correct |
46 |
Correct |
177 ms |
19832 KB |
Output is correct |
47 |
Correct |
134 ms |
20412 KB |
Output is correct |
48 |
Correct |
143 ms |
20420 KB |
Output is correct |
49 |
Correct |
176 ms |
20916 KB |
Output is correct |
50 |
Correct |
177 ms |
20940 KB |
Output is correct |
51 |
Correct |
175 ms |
20884 KB |
Output is correct |
52 |
Correct |
188 ms |
21016 KB |
Output is correct |
53 |
Correct |
195 ms |
20956 KB |
Output is correct |