#include<bits/stdc++.h>
using namespace std;
#define int long long
#define st first
#define nd second
const int maxn = 2e5 + 5;
int ans[maxn], b[maxn], st[maxn * 4], n;
pair<int, int> a[maxn];
void build(int id, int l, int r){
if(l == r){
st[id] = max(a[l + 1].st - b[l], 0ll);
return;
}
int m = (l + r) >> 1;
build(id * 2, l, m);
build(id * 2 + 1, m + 1, r);
st[id] = max(st[id * 2], st[id * 2 + 1]);
}
void update(int id, int l, int r, int pos){
if(l > pos || r < pos)
return;
if(l == r){
st[id] = max(a[l].st - b[l], 0ll);
return;
}
int m = (l + r) >> 1;
update(id * 2, l, m, pos);
update(id * 2 + 1, m + 1, r, pos);
st[id] = max(st[id * 2], st[id * 2 + 1]);
}
signed main(){
cin.tie(0)->sync_with_stdio(0);
cin >> n;
for(int i = 1 ; i <= n + 1 ; i++){
cin >> a[i].st;
a[i].nd = i;
}
for(int i = 1 ; i <= n ; i++)
cin >> b[i];
sort(a + 1, a + n + 2);
sort(b + 1, b + n + 1);
build(1, 1, n);
ans[a[1].nd] = st[1];
for(int i = 2 ; i <= n + 1 ; i++){
update(1, 1, n, i - 1);
ans[a[i].nd] = st[1];
}
for(int i = 1 ; i <= n + 1 ; i++)
cout << ans[i] << " ";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
352 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
0 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
352 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
0 ms |
340 KB |
Output is correct |
13 |
Correct |
0 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
0 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
2 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
2 ms |
340 KB |
Output is correct |
21 |
Correct |
2 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
340 KB |
Output is correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
1 ms |
340 KB |
Output is correct |
31 |
Correct |
1 ms |
340 KB |
Output is correct |
32 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
352 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
0 ms |
340 KB |
Output is correct |
13 |
Correct |
0 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
0 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
2 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
2 ms |
340 KB |
Output is correct |
21 |
Correct |
2 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
340 KB |
Output is correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
1 ms |
340 KB |
Output is correct |
31 |
Correct |
1 ms |
340 KB |
Output is correct |
32 |
Correct |
1 ms |
340 KB |
Output is correct |
33 |
Correct |
100 ms |
11868 KB |
Output is correct |
34 |
Correct |
106 ms |
12176 KB |
Output is correct |
35 |
Correct |
99 ms |
11968 KB |
Output is correct |
36 |
Correct |
98 ms |
12408 KB |
Output is correct |
37 |
Correct |
97 ms |
12552 KB |
Output is correct |
38 |
Correct |
110 ms |
12484 KB |
Output is correct |
39 |
Correct |
95 ms |
11552 KB |
Output is correct |
40 |
Correct |
99 ms |
11524 KB |
Output is correct |
41 |
Correct |
105 ms |
11664 KB |
Output is correct |
42 |
Correct |
99 ms |
11688 KB |
Output is correct |
43 |
Correct |
94 ms |
11532 KB |
Output is correct |
44 |
Correct |
92 ms |
11212 KB |
Output is correct |
45 |
Correct |
103 ms |
11232 KB |
Output is correct |
46 |
Correct |
92 ms |
11200 KB |
Output is correct |
47 |
Correct |
102 ms |
11188 KB |
Output is correct |
48 |
Correct |
90 ms |
11212 KB |
Output is correct |
49 |
Correct |
99 ms |
11792 KB |
Output is correct |
50 |
Correct |
98 ms |
11800 KB |
Output is correct |
51 |
Correct |
97 ms |
11804 KB |
Output is correct |
52 |
Correct |
98 ms |
11836 KB |
Output is correct |
53 |
Correct |
97 ms |
11740 KB |
Output is correct |