#include <bits/stdc++.h>
#define int long long int
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define pi pair<int, int>
#define INF 1e13
using namespace std;
int N, A[200010], B[200010], ans[200010];
pi as[200010];
struct node {
int s, e, m, val;
node *l, *r;
node (int _s, int _e) {
s = _s; e = _e;
m = (s + e) / 2;
val = 0;
if (s != e) {
l = new node(s, m);
r = new node(m + 1, e);
}
}
int query(int _s, int _e) {
if (s == _s and e == _e) {
return val;
}
else if (_e <= m) {
return l -> query(_s, _e);
}
else if (_s > m) {
return r-> query(_s, _e);
}
else {
return max(l -> query(_s, m), r -> query(m + 1, _e));
}
}
void update(int p, int v) {
if (s == p and e == p) {
val = v;
}
else {
if (p <= m) l -> update(p, v);
else r -> update(p, v);
val = max(l -> val, r -> val);
}
}
void children() {
if (s != e) {
l = new node(s, m);
r = new node(m + 1, e);
}
}
} *l, *r, *m;
int32_t main() {
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
cin >> N;
for (int i = 0; i < N + 1; i++) {
cin >> A[i];
as[i] = { A[i], i };
}
for (int i = 0; i < N; i++) {
cin >> B[i];
}
l = new node(0, N - 1);
m = new node(0, N - 1);
r = new node(0, N - 1);
sort(A, A + N + 1);
sort(as, as + N + 1);
sort(B, B + N);
for (int i = 0; i < N; i++) {
m -> update(i, max(A[i] - B[i], 0ll));
r -> update(i, max(A[i + 1] - B[i], 0ll));
}
for (int i = 0; i < N + 1; i++) {
int a = -INF, b = -INF;
if (i - 1 >= 0) a = m -> query(0, i - 1);
if (i <= N - 1) b = r -> query(i, N - 1);
ans[as[i].S] = max(a, b);
}
for (int i = 0; i < N + 1; i++) {
cout << ans[i] << " ";
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
4440 KB |
Output is correct |
8 |
Correct |
1 ms |
4444 KB |
Output is correct |
9 |
Correct |
1 ms |
4444 KB |
Output is correct |
10 |
Correct |
1 ms |
4440 KB |
Output is correct |
11 |
Correct |
1 ms |
4444 KB |
Output is correct |
12 |
Correct |
1 ms |
4444 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
4440 KB |
Output is correct |
8 |
Correct |
1 ms |
4444 KB |
Output is correct |
9 |
Correct |
1 ms |
4444 KB |
Output is correct |
10 |
Correct |
1 ms |
4440 KB |
Output is correct |
11 |
Correct |
1 ms |
4444 KB |
Output is correct |
12 |
Correct |
1 ms |
4444 KB |
Output is correct |
13 |
Correct |
1 ms |
4440 KB |
Output is correct |
14 |
Correct |
2 ms |
4700 KB |
Output is correct |
15 |
Correct |
3 ms |
4956 KB |
Output is correct |
16 |
Correct |
1 ms |
4444 KB |
Output is correct |
17 |
Correct |
2 ms |
5136 KB |
Output is correct |
18 |
Correct |
2 ms |
5212 KB |
Output is correct |
19 |
Correct |
2 ms |
5212 KB |
Output is correct |
20 |
Correct |
2 ms |
5212 KB |
Output is correct |
21 |
Correct |
2 ms |
5208 KB |
Output is correct |
22 |
Correct |
2 ms |
5212 KB |
Output is correct |
23 |
Correct |
2 ms |
5212 KB |
Output is correct |
24 |
Correct |
2 ms |
5212 KB |
Output is correct |
25 |
Correct |
2 ms |
5208 KB |
Output is correct |
26 |
Correct |
2 ms |
5212 KB |
Output is correct |
27 |
Correct |
3 ms |
5212 KB |
Output is correct |
28 |
Correct |
2 ms |
5212 KB |
Output is correct |
29 |
Correct |
2 ms |
5212 KB |
Output is correct |
30 |
Correct |
2 ms |
5076 KB |
Output is correct |
31 |
Correct |
2 ms |
5348 KB |
Output is correct |
32 |
Correct |
2 ms |
5208 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
4440 KB |
Output is correct |
8 |
Correct |
1 ms |
4444 KB |
Output is correct |
9 |
Correct |
1 ms |
4444 KB |
Output is correct |
10 |
Correct |
1 ms |
4440 KB |
Output is correct |
11 |
Correct |
1 ms |
4444 KB |
Output is correct |
12 |
Correct |
1 ms |
4444 KB |
Output is correct |
13 |
Correct |
1 ms |
4440 KB |
Output is correct |
14 |
Correct |
2 ms |
4700 KB |
Output is correct |
15 |
Correct |
3 ms |
4956 KB |
Output is correct |
16 |
Correct |
1 ms |
4444 KB |
Output is correct |
17 |
Correct |
2 ms |
5136 KB |
Output is correct |
18 |
Correct |
2 ms |
5212 KB |
Output is correct |
19 |
Correct |
2 ms |
5212 KB |
Output is correct |
20 |
Correct |
2 ms |
5212 KB |
Output is correct |
21 |
Correct |
2 ms |
5208 KB |
Output is correct |
22 |
Correct |
2 ms |
5212 KB |
Output is correct |
23 |
Correct |
2 ms |
5212 KB |
Output is correct |
24 |
Correct |
2 ms |
5212 KB |
Output is correct |
25 |
Correct |
2 ms |
5208 KB |
Output is correct |
26 |
Correct |
2 ms |
5212 KB |
Output is correct |
27 |
Correct |
3 ms |
5212 KB |
Output is correct |
28 |
Correct |
2 ms |
5212 KB |
Output is correct |
29 |
Correct |
2 ms |
5212 KB |
Output is correct |
30 |
Correct |
2 ms |
5076 KB |
Output is correct |
31 |
Correct |
2 ms |
5348 KB |
Output is correct |
32 |
Correct |
2 ms |
5208 KB |
Output is correct |
33 |
Correct |
170 ms |
84820 KB |
Output is correct |
34 |
Correct |
181 ms |
88172 KB |
Output is correct |
35 |
Correct |
186 ms |
85332 KB |
Output is correct |
36 |
Correct |
188 ms |
86348 KB |
Output is correct |
37 |
Correct |
182 ms |
88920 KB |
Output is correct |
38 |
Correct |
207 ms |
87980 KB |
Output is correct |
39 |
Correct |
192 ms |
86196 KB |
Output is correct |
40 |
Correct |
174 ms |
85588 KB |
Output is correct |
41 |
Correct |
181 ms |
86868 KB |
Output is correct |
42 |
Correct |
196 ms |
86424 KB |
Output is correct |
43 |
Correct |
174 ms |
85888 KB |
Output is correct |
44 |
Correct |
179 ms |
84208 KB |
Output is correct |
45 |
Correct |
175 ms |
85072 KB |
Output is correct |
46 |
Correct |
172 ms |
84304 KB |
Output is correct |
47 |
Correct |
184 ms |
87636 KB |
Output is correct |
48 |
Correct |
181 ms |
87756 KB |
Output is correct |
49 |
Correct |
189 ms |
88296 KB |
Output is correct |
50 |
Correct |
184 ms |
88400 KB |
Output is correct |
51 |
Correct |
185 ms |
88380 KB |
Output is correct |
52 |
Correct |
184 ms |
88292 KB |
Output is correct |
53 |
Correct |
196 ms |
88248 KB |
Output is correct |