#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define int long long
#define f first
#define s second
#define pii pair<int,int>
#define piii pair<int,pair<int,int>>
#define vii vector<vector<int>>
#define vi vector<int>
#define cd complex<double>
#define endl '\n'
//#define multipletest
using namespace std;
const int LIM=2e5;
const int INF = 1e18;
const string name="neckties";
int n,m;
int b[LIM+5];
int ans[LIM+5];
vector<pii> a;
int st1[4*LIM+5];
int st2[4*LIM+5];
int bound;
int merge(int a,int b){
//CODE MERGE
return max(a,b);
}
void build1(int id,int ss,int se){
//BUID INITTIALLY TREE
if(ss==se){
st1[id]=max(0ll,a[ss].f - b[ss-1]);
return;
}
int mid=(ss+se)>>1;
build1(2*id+1,ss,mid);
build1(2*id+2,mid+1,se);
st1[id]=merge(st1[2*id+1],st1[2*id+2]);
}
int _query1(int id,int ss,int se,int qs,int qe){
//PROCESS
if(ss>qe || se<qs){
return -INF;
}
if(qs<=ss && qe>=se){
// UPDATE NODE;
return st1[id];
}
int mid=(ss+se)>>1;
int left_child=_query1(2*id+1,ss,mid,qs,qe);
int right_child=_query1(2*id+2,mid+1,se,qs,qe);
return merge(left_child,right_child);
}
int query1(int qs,int qe){
return _query1(0,1,bound,qs,qe);
}
void build2(int id,int ss,int se){
//BUID INITTIALLY TREE
if(ss==se){
st2[id]=max(0ll,a[ss].f - b[ss]);
return;
}
int mid=(ss+se)>>1;
build2(2*id+1,ss,mid);
build2(2*id+2,mid+1,se);
st2[id]=merge(st2[2*id+1],st2[2*id+2]);
}
int _query2(int id,int ss,int se,int qs,int qe){
//PROCESS
if(ss>qe || se<qs){
return -INF;
}
if(qs<=ss && qe>=se){
// UPDATE NODE;
return st2[id];
}
int mid=(ss+se)>>1;
int left_child=_query2(2*id+1,ss,mid,qs,qe);
int right_child=_query2(2*id+2,mid+1,se,qs,qe);
return merge(left_child,right_child);
}
int query2(int qs,int qe){
return _query2(0,0,bound-1,qs,qe);
}
void solve(){
//CODE GOES HERE
cin>>n;
for(int i=0;i<=n;++i){
int x;
cin>>x;
a.push_back({x,i});
}
for(int i=0;i<n;++i){
cin>>b[i];
}
sort(a.begin(),a.end());
sort(b,b+n);
build1(0,1,n);
build2(0,0,n-1);
bound = n;
vector<int> v;
// cout<<query2(0ll,0ll)<<endl;
for(int i=0;i<=n;++i){
if(i==0){
ans[a[i].s] = st1[0];
}
else if(i<n){
ans[a[i].s] = max(query2(0,i-1),query1(i+1,n));
}
else{
ans[a[i].s]=query2(0ll,n-1);
}
}
for(int i=0;i<=n;++i){
cout<<ans[i]<<" ";
}
}
signed main(){
// freopen((name+".inp").c_str(),"r",stdin);
// freopen((name+".out").c_str(),"w",stdout);
// ifstream cin(".txt");
// ofstream cout(".txt");
//ifstream cin((name +".inp"));
//ofstream cout((name +".ans"));
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int test;
test=1;
#ifdef multipletest
cin>>test;
#endif
while(test--){
solve();
#ifdef DEBUG
cerr << "Runtime is: " << clock() * 1.0 / CLOCKS_PER_SEC << endl;
#endif
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 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 |
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 |
0 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 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 |
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 |
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 |
468 KB |
Output is correct |
16 |
Correct |
0 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
468 KB |
Output is correct |
18 |
Correct |
1 ms |
468 KB |
Output is correct |
19 |
Correct |
1 ms |
468 KB |
Output is correct |
20 |
Correct |
1 ms |
468 KB |
Output is correct |
21 |
Correct |
1 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 |
1 ms |
468 KB |
Output is correct |
25 |
Correct |
1 ms |
468 KB |
Output is correct |
26 |
Correct |
1 ms |
468 KB |
Output is correct |
27 |
Correct |
2 ms |
468 KB |
Output is correct |
28 |
Correct |
1 ms |
468 KB |
Output is correct |
29 |
Correct |
1 ms |
468 KB |
Output is correct |
30 |
Correct |
1 ms |
468 KB |
Output is correct |
31 |
Correct |
1 ms |
468 KB |
Output is correct |
32 |
Correct |
1 ms |
468 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 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 |
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 |
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 |
468 KB |
Output is correct |
16 |
Correct |
0 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
468 KB |
Output is correct |
18 |
Correct |
1 ms |
468 KB |
Output is correct |
19 |
Correct |
1 ms |
468 KB |
Output is correct |
20 |
Correct |
1 ms |
468 KB |
Output is correct |
21 |
Correct |
1 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 |
1 ms |
468 KB |
Output is correct |
25 |
Correct |
1 ms |
468 KB |
Output is correct |
26 |
Correct |
1 ms |
468 KB |
Output is correct |
27 |
Correct |
2 ms |
468 KB |
Output is correct |
28 |
Correct |
1 ms |
468 KB |
Output is correct |
29 |
Correct |
1 ms |
468 KB |
Output is correct |
30 |
Correct |
1 ms |
468 KB |
Output is correct |
31 |
Correct |
1 ms |
468 KB |
Output is correct |
32 |
Correct |
1 ms |
468 KB |
Output is correct |
33 |
Correct |
124 ms |
16048 KB |
Output is correct |
34 |
Correct |
124 ms |
16456 KB |
Output is correct |
35 |
Correct |
118 ms |
16104 KB |
Output is correct |
36 |
Correct |
150 ms |
16652 KB |
Output is correct |
37 |
Correct |
125 ms |
16948 KB |
Output is correct |
38 |
Correct |
122 ms |
16740 KB |
Output is correct |
39 |
Correct |
118 ms |
15920 KB |
Output is correct |
40 |
Correct |
117 ms |
15888 KB |
Output is correct |
41 |
Correct |
152 ms |
15956 KB |
Output is correct |
42 |
Correct |
117 ms |
15928 KB |
Output is correct |
43 |
Correct |
118 ms |
15780 KB |
Output is correct |
44 |
Correct |
137 ms |
15564 KB |
Output is correct |
45 |
Correct |
118 ms |
15604 KB |
Output is correct |
46 |
Correct |
115 ms |
15444 KB |
Output is correct |
47 |
Correct |
114 ms |
15460 KB |
Output is correct |
48 |
Correct |
114 ms |
15396 KB |
Output is correct |
49 |
Correct |
120 ms |
16088 KB |
Output is correct |
50 |
Correct |
123 ms |
16088 KB |
Output is correct |
51 |
Correct |
139 ms |
16040 KB |
Output is correct |
52 |
Correct |
120 ms |
16024 KB |
Output is correct |
53 |
Correct |
123 ms |
16044 KB |
Output is correct |