#include<bits/stdc++.h>
#define endl '\n'
#define int long long
#define mod 1000000007
#define boost ios_base::sync_with_stdio(false), cin.tie(NULL);
using namespace std;
int N,Left,Right,Type;
pair<int,int>a[4000001];
int b[4000001],ans[2000001];
int seg[4000001],seg2[4000001];
void Update(){
int ind = N + Left - 1;
seg[ind] = a[Left].first - b[Left - 1];
while(ind /= 2) seg[ind] = max(seg[ind * 2], seg[ind * 2 + 1]);
ind = N + Left - 1;
seg2[ind] = a[Left - 1].first - b[Left - 1];
while(ind /= 2) seg2[ind] = max(seg2[ind * 2], seg2[ind * 2 + 1]);
}
int Query(int l = 1, int r = N, int ind = 1){
if(l > Right || r < Left) return 0;
if(l >= Left && r <= Right){
if(Type) return seg[ind];
return seg2[ind];
}
int mid = (l + r) / 2;
return max(Query(l, mid, ind * 2), Query(mid + 1, r, ind * 2 + 1));
}
signed main(){
boost;
int n; cin >> n;
N = exp2(ceil(log2(n)));
for(int i = 0; i < n + 1; i++){
cin >> a[i].first;
a[i].second = i;
}
sort(a,a+n+1);
for(int i = 0; i < n; i++) cin >> b[i];
sort(b,b+n);
for(int i = 0; i < n; i++){
Left = i + 1;
Update();
}
for(int i = 0; i < n + 1; i++){
int aa = 0;
Left = 1; Right = i;
if(Left <= Right){
Type = 0;
aa = max(aa,Query());
}
Left = i + 1; Right = n;
if(Left <= Right){
Type = 1;
aa = max(aa,Query());
}
ans[a[i].second] = aa;
}
for(int i = 0; i < n + 1; i++) cout << ans[i] << ' ';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
0 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 |
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 |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
0 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 |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
2 ms |
340 KB |
Output is correct |
15 |
Correct |
2 ms |
464 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
2 ms |
468 KB |
Output is correct |
18 |
Correct |
2 ms |
468 KB |
Output is correct |
19 |
Correct |
2 ms |
468 KB |
Output is correct |
20 |
Correct |
2 ms |
468 KB |
Output is correct |
21 |
Correct |
2 ms |
468 KB |
Output is correct |
22 |
Correct |
2 ms |
468 KB |
Output is correct |
23 |
Correct |
1 ms |
468 KB |
Output is correct |
24 |
Correct |
2 ms |
468 KB |
Output is correct |
25 |
Correct |
2 ms |
468 KB |
Output is correct |
26 |
Correct |
2 ms |
468 KB |
Output is correct |
27 |
Correct |
2 ms |
468 KB |
Output is correct |
28 |
Correct |
2 ms |
468 KB |
Output is correct |
29 |
Correct |
2 ms |
468 KB |
Output is correct |
30 |
Correct |
2 ms |
468 KB |
Output is correct |
31 |
Correct |
2 ms |
480 KB |
Output is correct |
32 |
Correct |
2 ms |
468 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 |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
0 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 |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
2 ms |
340 KB |
Output is correct |
15 |
Correct |
2 ms |
464 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
2 ms |
468 KB |
Output is correct |
18 |
Correct |
2 ms |
468 KB |
Output is correct |
19 |
Correct |
2 ms |
468 KB |
Output is correct |
20 |
Correct |
2 ms |
468 KB |
Output is correct |
21 |
Correct |
2 ms |
468 KB |
Output is correct |
22 |
Correct |
2 ms |
468 KB |
Output is correct |
23 |
Correct |
1 ms |
468 KB |
Output is correct |
24 |
Correct |
2 ms |
468 KB |
Output is correct |
25 |
Correct |
2 ms |
468 KB |
Output is correct |
26 |
Correct |
2 ms |
468 KB |
Output is correct |
27 |
Correct |
2 ms |
468 KB |
Output is correct |
28 |
Correct |
2 ms |
468 KB |
Output is correct |
29 |
Correct |
2 ms |
468 KB |
Output is correct |
30 |
Correct |
2 ms |
468 KB |
Output is correct |
31 |
Correct |
2 ms |
480 KB |
Output is correct |
32 |
Correct |
2 ms |
468 KB |
Output is correct |
33 |
Correct |
197 ms |
13732 KB |
Output is correct |
34 |
Correct |
191 ms |
14364 KB |
Output is correct |
35 |
Correct |
180 ms |
13968 KB |
Output is correct |
36 |
Correct |
193 ms |
14392 KB |
Output is correct |
37 |
Correct |
179 ms |
14852 KB |
Output is correct |
38 |
Correct |
191 ms |
14672 KB |
Output is correct |
39 |
Correct |
167 ms |
13720 KB |
Output is correct |
40 |
Correct |
166 ms |
13616 KB |
Output is correct |
41 |
Correct |
190 ms |
13804 KB |
Output is correct |
42 |
Correct |
166 ms |
13772 KB |
Output is correct |
43 |
Correct |
171 ms |
13576 KB |
Output is correct |
44 |
Correct |
184 ms |
13228 KB |
Output is correct |
45 |
Correct |
161 ms |
13260 KB |
Output is correct |
46 |
Correct |
171 ms |
13232 KB |
Output is correct |
47 |
Correct |
181 ms |
13436 KB |
Output is correct |
48 |
Correct |
157 ms |
13444 KB |
Output is correct |
49 |
Correct |
181 ms |
14080 KB |
Output is correct |
50 |
Correct |
177 ms |
14064 KB |
Output is correct |
51 |
Correct |
180 ms |
14104 KB |
Output is correct |
52 |
Correct |
205 ms |
14084 KB |
Output is correct |
53 |
Correct |
190 ms |
14000 KB |
Output is correct |