#include<bits/stdc++.h>
using namespace std;
#define taskname "template"
#define ll long long
#define ld double
#define fi first
#define se second
#define vi vector<int>
#define pii pair<int,int>
#define vii vector<pii>
#define vvi vector<vi>
#define pb push_back
#define eb emplace_back
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
const int MN=2e5+5;
int n;
pair<ll,int> new_arr[MN+1];
ll arr[MN];//the value is new_arr[i]-arr[i]
ll arr2[MN+1];
map<int,int> mp;
ll left_st[MN<<2],right_st[MN<<2];//not update and update
void build(int id,int l,int r){
if(l==r){
left_st[id]=arr[l];
right_st[id]=arr2[l];
/*
cout<<"Case "<<l<<' '<<r<<": \n";
cout<<"left: "<<left_st[id]<<'\n';
cout<<"right: "<<right_st[id]<<'\n';
*/
return;
}
int mid=l+r>>1;
build(id<<1,l,mid);
build(id<<1|1,mid+1,r);
left_st[id]=max(left_st[id<<1],left_st[id<<1|1]);
right_st[id]=max(right_st[id<<1],right_st[id<<1|1]);
/*
cout<<"Case "<<l<<' '<<r<<": \n";
cout<<"left: "<<left_st[id]<<'\n';
cout<<"right: "<<right_st[id]<<'\n';
*/
}
ll get_left(int id,int l,int r,int tl,int tr){
if(tl>tr) return (ll)0;
if(tl>r||l>tr) return (ll)0;
if(tl<=l&&r<=tr) return left_st[id];
int mid=l+r>>1;
ll get1=get_left(id<<1,l,mid,tl,tr);
ll get2=get_left(id<<1|1,mid+1,r,tl,tr);
return max(get1,get2);
}
ll get_right(int id,int l,int r,int tl,int tr){
if(tl>tr) return (ll)0;
if(tl>r||l>tr) return (ll)0;
if(tl<=l&&r<=tr) return right_st[id];
int mid=l+r>>1;
ll get1=get_right(id<<1,l,mid,tl,tr);
ll get2=get_right(id<<1|1,mid+1,r,tl,tr);
return max(get1,get2);
}
int main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
/*
freopen(taskname".inp","r",stdin);
freopen(taskname".out","w",stdout);
*/
cin>>n;
for(int i=1;i<=n+1;++i){
cin>>new_arr[i].fi;
new_arr[i].se=i;
}
for(int i=1;i<=n;++i){
cin>>arr[i];
}
sort(arr+1,arr+1+n);
sort(new_arr+1,new_arr+1+n+1);
for(int i=1;i<=n+1;++i){
mp[new_arr[i].se]=i;
}
for(int i=2;i<=n+1;++i){
arr2[i]=max((ll)0,new_arr[i].fi-arr[i-1]);
}
for(int i=1;i<=n;++i){
arr[i]=max((ll)0,new_arr[i].fi-arr[i]);
}
/*
for(int i=1;i<=n+1;++i){
cout<<arr2[i]<<' ';
}
*/
build(1,1,n+1);
for(int i=1;i<=n+1;++i){
int idx=mp[i];
ll get1=get_left(1,1,n+1,1,idx-1);
ll get2=get_right(1,1,n+1,idx+1,n+1);
cout<<max(get1,get2)<<' ';
}
}
Compilation message
ho_t1.cpp: In function 'void build(int, int, int)':
ho_t1.cpp:38:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
38 | int mid=l+r>>1;
| ~^~
ho_t1.cpp: In function 'long long int get_left(int, int, int, int, int)':
ho_t1.cpp:56:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
56 | int mid=l+r>>1;
| ~^~
ho_t1.cpp: In function 'long long int get_right(int, int, int, int, int)':
ho_t1.cpp:68:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
68 | int mid=l+r>>1;
| ~^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
0 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
0 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
468 KB |
Output is correct |
15 |
Correct |
2 ms |
468 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
2 ms |
608 KB |
Output is correct |
18 |
Correct |
2 ms |
468 KB |
Output is correct |
19 |
Correct |
2 ms |
596 KB |
Output is correct |
20 |
Correct |
2 ms |
480 KB |
Output is correct |
21 |
Correct |
2 ms |
596 KB |
Output is correct |
22 |
Correct |
2 ms |
476 KB |
Output is correct |
23 |
Correct |
2 ms |
468 KB |
Output is correct |
24 |
Correct |
2 ms |
524 KB |
Output is correct |
25 |
Correct |
2 ms |
596 KB |
Output is correct |
26 |
Correct |
2 ms |
596 KB |
Output is correct |
27 |
Correct |
2 ms |
596 KB |
Output is correct |
28 |
Correct |
2 ms |
596 KB |
Output is correct |
29 |
Correct |
2 ms |
468 KB |
Output is correct |
30 |
Correct |
2 ms |
516 KB |
Output is correct |
31 |
Correct |
2 ms |
596 KB |
Output is correct |
32 |
Correct |
2 ms |
596 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
0 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
468 KB |
Output is correct |
15 |
Correct |
2 ms |
468 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
2 ms |
608 KB |
Output is correct |
18 |
Correct |
2 ms |
468 KB |
Output is correct |
19 |
Correct |
2 ms |
596 KB |
Output is correct |
20 |
Correct |
2 ms |
480 KB |
Output is correct |
21 |
Correct |
2 ms |
596 KB |
Output is correct |
22 |
Correct |
2 ms |
476 KB |
Output is correct |
23 |
Correct |
2 ms |
468 KB |
Output is correct |
24 |
Correct |
2 ms |
524 KB |
Output is correct |
25 |
Correct |
2 ms |
596 KB |
Output is correct |
26 |
Correct |
2 ms |
596 KB |
Output is correct |
27 |
Correct |
2 ms |
596 KB |
Output is correct |
28 |
Correct |
2 ms |
596 KB |
Output is correct |
29 |
Correct |
2 ms |
468 KB |
Output is correct |
30 |
Correct |
2 ms |
516 KB |
Output is correct |
31 |
Correct |
2 ms |
596 KB |
Output is correct |
32 |
Correct |
2 ms |
596 KB |
Output is correct |
33 |
Correct |
242 ms |
25124 KB |
Output is correct |
34 |
Correct |
280 ms |
25784 KB |
Output is correct |
35 |
Correct |
245 ms |
25148 KB |
Output is correct |
36 |
Correct |
224 ms |
25728 KB |
Output is correct |
37 |
Correct |
277 ms |
26252 KB |
Output is correct |
38 |
Correct |
276 ms |
26064 KB |
Output is correct |
39 |
Correct |
225 ms |
24992 KB |
Output is correct |
40 |
Correct |
257 ms |
24952 KB |
Output is correct |
41 |
Correct |
221 ms |
25040 KB |
Output is correct |
42 |
Correct |
268 ms |
25036 KB |
Output is correct |
43 |
Correct |
248 ms |
25096 KB |
Output is correct |
44 |
Correct |
215 ms |
24384 KB |
Output is correct |
45 |
Correct |
218 ms |
24576 KB |
Output is correct |
46 |
Correct |
229 ms |
24376 KB |
Output is correct |
47 |
Correct |
202 ms |
24856 KB |
Output is correct |
48 |
Correct |
167 ms |
24848 KB |
Output is correct |
49 |
Correct |
234 ms |
25596 KB |
Output is correct |
50 |
Correct |
236 ms |
25468 KB |
Output is correct |
51 |
Correct |
240 ms |
25524 KB |
Output is correct |
52 |
Correct |
234 ms |
25420 KB |
Output is correct |
53 |
Correct |
253 ms |
25492 KB |
Output is correct |