#include<bits/stdc++.h>
#define pii pair<int,int>
#define ll long long
#define f first
#define s second
using namespace std;
const int mxn=2e5+6;
int tree[4*mxn]={};
int query(int node,int b,int e,int p,int v=0)
{
if(b==e)return max(v,tree[node]);
int mid=b+e>>1;
if(p<=mid)return query(node<<1,b,mid,p,max(v,tree[node]));
else return query(node*2+1,mid+1,e,p,max(v,tree[node]));
}
void update(int node, int b,int e,int l,int r,int v)
{
if(b>r || e<l)return;
if(b>=l && e<=r)
{
tree[node]=max(tree[node],v);
return;
}
int mid=b+e>>1;
int left=node<<1;
int right=left|1;
update(left,b,mid,l,r,v);
update(right,mid+1,e,l,r,v);
}
int main()
{
int n;
cin>>n;
pii a[mxn];
int b[mxn];
for(int i=1;i<=n+1;i++)
{
cin>>a[i].f;
a[i].s=i;
}
sort(a+1,a+n+2);
for(int i=1;i<=n;i++)cin>>b[i];
sort(b+1,b+n+1);
for(int i=1;i<=n;i++)
{
int d1=max(a[i].f-b[i],0);
int d2=max(a[i+1].f-b[i],0);
update(1,1,n+1,1,i,d2);
update(1,1,n+1,i+1,n+1,d1);
}
int res[mxn];
for(int i=1;i<=n+1;i++)
{
res[a[i].s]=query(1,1,n+1,i);
}
for(int i=1;i<=n+1;i++)cout<<res[i]<<" ";
return 0;
}
Compilation message
ho_t1.cpp: In function 'int query(int, int, int, int, int)':
ho_t1.cpp:15:11: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
int mid=b+e>>1;
~^~
ho_t1.cpp: In function 'void update(int, int, int, int, int, int)':
ho_t1.cpp:29:11: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
int mid=b+e>>1;
~^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
1912 KB |
Output is correct |
2 |
Correct |
6 ms |
1912 KB |
Output is correct |
3 |
Correct |
5 ms |
1784 KB |
Output is correct |
4 |
Correct |
6 ms |
2040 KB |
Output is correct |
5 |
Correct |
5 ms |
1912 KB |
Output is correct |
6 |
Correct |
5 ms |
1912 KB |
Output is correct |
7 |
Correct |
6 ms |
1912 KB |
Output is correct |
8 |
Correct |
5 ms |
1912 KB |
Output is correct |
9 |
Correct |
6 ms |
2040 KB |
Output is correct |
10 |
Correct |
6 ms |
1912 KB |
Output is correct |
11 |
Correct |
6 ms |
1912 KB |
Output is correct |
12 |
Correct |
6 ms |
1912 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
1912 KB |
Output is correct |
2 |
Correct |
6 ms |
1912 KB |
Output is correct |
3 |
Correct |
5 ms |
1784 KB |
Output is correct |
4 |
Correct |
6 ms |
2040 KB |
Output is correct |
5 |
Correct |
5 ms |
1912 KB |
Output is correct |
6 |
Correct |
5 ms |
1912 KB |
Output is correct |
7 |
Correct |
6 ms |
1912 KB |
Output is correct |
8 |
Correct |
5 ms |
1912 KB |
Output is correct |
9 |
Correct |
6 ms |
2040 KB |
Output is correct |
10 |
Correct |
6 ms |
1912 KB |
Output is correct |
11 |
Correct |
6 ms |
1912 KB |
Output is correct |
12 |
Correct |
6 ms |
1912 KB |
Output is correct |
13 |
Correct |
6 ms |
1912 KB |
Output is correct |
14 |
Correct |
7 ms |
1916 KB |
Output is correct |
15 |
Correct |
8 ms |
1960 KB |
Output is correct |
16 |
Correct |
6 ms |
1912 KB |
Output is correct |
17 |
Correct |
9 ms |
1912 KB |
Output is correct |
18 |
Correct |
8 ms |
1916 KB |
Output is correct |
19 |
Correct |
8 ms |
1912 KB |
Output is correct |
20 |
Correct |
8 ms |
1912 KB |
Output is correct |
21 |
Correct |
8 ms |
1912 KB |
Output is correct |
22 |
Correct |
8 ms |
1912 KB |
Output is correct |
23 |
Correct |
8 ms |
1912 KB |
Output is correct |
24 |
Correct |
8 ms |
1916 KB |
Output is correct |
25 |
Correct |
9 ms |
1912 KB |
Output is correct |
26 |
Correct |
9 ms |
1912 KB |
Output is correct |
27 |
Correct |
9 ms |
1912 KB |
Output is correct |
28 |
Correct |
8 ms |
1912 KB |
Output is correct |
29 |
Correct |
8 ms |
1912 KB |
Output is correct |
30 |
Correct |
9 ms |
1916 KB |
Output is correct |
31 |
Correct |
8 ms |
1912 KB |
Output is correct |
32 |
Correct |
9 ms |
1916 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
1912 KB |
Output is correct |
2 |
Correct |
6 ms |
1912 KB |
Output is correct |
3 |
Correct |
5 ms |
1784 KB |
Output is correct |
4 |
Correct |
6 ms |
2040 KB |
Output is correct |
5 |
Correct |
5 ms |
1912 KB |
Output is correct |
6 |
Correct |
5 ms |
1912 KB |
Output is correct |
7 |
Correct |
6 ms |
1912 KB |
Output is correct |
8 |
Correct |
5 ms |
1912 KB |
Output is correct |
9 |
Correct |
6 ms |
2040 KB |
Output is correct |
10 |
Correct |
6 ms |
1912 KB |
Output is correct |
11 |
Correct |
6 ms |
1912 KB |
Output is correct |
12 |
Correct |
6 ms |
1912 KB |
Output is correct |
13 |
Correct |
6 ms |
1912 KB |
Output is correct |
14 |
Correct |
7 ms |
1916 KB |
Output is correct |
15 |
Correct |
8 ms |
1960 KB |
Output is correct |
16 |
Correct |
6 ms |
1912 KB |
Output is correct |
17 |
Correct |
9 ms |
1912 KB |
Output is correct |
18 |
Correct |
8 ms |
1916 KB |
Output is correct |
19 |
Correct |
8 ms |
1912 KB |
Output is correct |
20 |
Correct |
8 ms |
1912 KB |
Output is correct |
21 |
Correct |
8 ms |
1912 KB |
Output is correct |
22 |
Correct |
8 ms |
1912 KB |
Output is correct |
23 |
Correct |
8 ms |
1912 KB |
Output is correct |
24 |
Correct |
8 ms |
1916 KB |
Output is correct |
25 |
Correct |
9 ms |
1912 KB |
Output is correct |
26 |
Correct |
9 ms |
1912 KB |
Output is correct |
27 |
Correct |
9 ms |
1912 KB |
Output is correct |
28 |
Correct |
8 ms |
1912 KB |
Output is correct |
29 |
Correct |
8 ms |
1912 KB |
Output is correct |
30 |
Correct |
9 ms |
1916 KB |
Output is correct |
31 |
Correct |
8 ms |
1912 KB |
Output is correct |
32 |
Correct |
9 ms |
1916 KB |
Output is correct |
33 |
Correct |
341 ms |
6904 KB |
Output is correct |
34 |
Correct |
362 ms |
7160 KB |
Output is correct |
35 |
Correct |
346 ms |
7032 KB |
Output is correct |
36 |
Correct |
356 ms |
7440 KB |
Output is correct |
37 |
Correct |
353 ms |
7544 KB |
Output is correct |
38 |
Correct |
355 ms |
7416 KB |
Output is correct |
39 |
Correct |
350 ms |
6648 KB |
Output is correct |
40 |
Correct |
342 ms |
6652 KB |
Output is correct |
41 |
Correct |
360 ms |
6652 KB |
Output is correct |
42 |
Correct |
358 ms |
6776 KB |
Output is correct |
43 |
Correct |
354 ms |
6612 KB |
Output is correct |
44 |
Correct |
348 ms |
6392 KB |
Output is correct |
45 |
Correct |
348 ms |
6392 KB |
Output is correct |
46 |
Correct |
338 ms |
6392 KB |
Output is correct |
47 |
Correct |
360 ms |
6224 KB |
Output is correct |
48 |
Correct |
359 ms |
6008 KB |
Output is correct |
49 |
Correct |
355 ms |
6652 KB |
Output is correct |
50 |
Correct |
353 ms |
6648 KB |
Output is correct |
51 |
Correct |
359 ms |
6648 KB |
Output is correct |
52 |
Correct |
377 ms |
6648 KB |
Output is correct |
53 |
Correct |
363 ms |
6904 KB |
Output is correct |