#include<iostream>
#include<vector>
#include<algorithm>
#include<utility>
using namespace std;
int t[300000];
int drzewo[1000000];
int drzewo2[1000000];
int pot=1;
int wynik[300000];
int a[300000];
int b[300000];
vector<pair<int,int> > Q;
vector<int> Q2;
int zap1(int x,int y)
{
if(x>y)
return 0;
x+=pot;
y+=pot;
int wynik=0;
wynik=max(drzewo[x],drzewo[y]);
while(x/2!=y/2)
{
if(x%2==0)
wynik=max(wynik,drzewo[x+1]);
if(y%2==1)
wynik=max(wynik,drzewo[y-1]);
x/=2;
y/=2;
}
return wynik;
}
int zap2(int x,int y)
{
if(x>y)
return 0;
x+=pot;
y+=pot;
int wynik=0;
wynik=max(drzewo2[x],drzewo2[y]);
while(x/2!=y/2)
{
if(x%2==0)
wynik=max(wynik,drzewo2[x+1]);
if(y%2==1)
wynik=max(wynik,drzewo2[y-1]);
x/=2;
y/=2;
}
return wynik;
}
int main()
{
cin.tie(0);
cout.tie(0);
ios_base::sync_with_stdio(0);
int n;
cin>>n;
while(pot<=n+1)
pot*=2;
pot--;
for(int i=1;i<=n+1;i++)
{
cin>>a[i];
Q.push_back({a[i],i});
}
sort(Q.begin(),Q.end());
for(int i=0;i<n;i++)
{
cin>>b[i];
Q2.push_back(b[i]);
}
sort(Q2.begin(),Q2.end());
for(int i=1;i<=n;i++)
b[i]=Q2[i-1];
for(int i=1;i<=n+1;i++)
{
//cout<<a[Q[i-1].second]<<" "<<b[i-1]<<" "<<b[i]<<"\n";
if(i<=n)
drzewo[i+pot]=a[Q[i-1].second]-b[i];
if(i>1)
drzewo2[i+pot]=a[Q[i-1].second]-b[i-1];
}
for(int i=pot;i>=1;i--)
drzewo[i]=max(drzewo[i*2],drzewo[i*2+1]);
for(int i=pot;i>=1;i--)
drzewo2[i]=max(drzewo2[i*2],drzewo2[i*2+1]);
for(int i=1;i<=n+1;i++)
{
//cout<<"na lewo "<<zap1(1,i-1)<<" "<<zap2(i+1,n)<<"\n";
//cout<<"usuwam "<<Q[i-1].second<<"\n";
wynik[Q[i-1].second]=max(zap1(1,i-1),zap2(i+1,n+1));
wynik[Q[i-1].second]=max(wynik[Q[i-1].second],0);
}
for(int i=1;i<=n+1;i++)
cout<<wynik[i]<<" ";
return 0;
}
# |
Verdict |
Execution time |
Memory |
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 |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
324 KB |
Output is correct |
10 |
Correct |
1 ms |
284 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
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 |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
324 KB |
Output is correct |
10 |
Correct |
1 ms |
284 KB |
Output is correct |
11 |
Correct |
1 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 |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
2 ms |
472 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 |
476 KB |
Output is correct |
22 |
Correct |
1 ms |
468 KB |
Output is correct |
23 |
Correct |
2 ms |
468 KB |
Output is correct |
24 |
Correct |
1 ms |
468 KB |
Output is correct |
25 |
Correct |
2 ms |
468 KB |
Output is correct |
26 |
Correct |
1 ms |
476 KB |
Output is correct |
27 |
Correct |
1 ms |
396 KB |
Output is correct |
28 |
Correct |
2 ms |
472 KB |
Output is correct |
29 |
Correct |
1 ms |
468 KB |
Output is correct |
30 |
Correct |
1 ms |
468 KB |
Output is correct |
31 |
Correct |
2 ms |
404 KB |
Output is correct |
32 |
Correct |
2 ms |
468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
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 |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
324 KB |
Output is correct |
10 |
Correct |
1 ms |
284 KB |
Output is correct |
11 |
Correct |
1 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 |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
2 ms |
472 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 |
476 KB |
Output is correct |
22 |
Correct |
1 ms |
468 KB |
Output is correct |
23 |
Correct |
2 ms |
468 KB |
Output is correct |
24 |
Correct |
1 ms |
468 KB |
Output is correct |
25 |
Correct |
2 ms |
468 KB |
Output is correct |
26 |
Correct |
1 ms |
476 KB |
Output is correct |
27 |
Correct |
1 ms |
396 KB |
Output is correct |
28 |
Correct |
2 ms |
472 KB |
Output is correct |
29 |
Correct |
1 ms |
468 KB |
Output is correct |
30 |
Correct |
1 ms |
468 KB |
Output is correct |
31 |
Correct |
2 ms |
404 KB |
Output is correct |
32 |
Correct |
2 ms |
468 KB |
Output is correct |
33 |
Correct |
118 ms |
14488 KB |
Output is correct |
34 |
Correct |
124 ms |
15088 KB |
Output is correct |
35 |
Correct |
113 ms |
14660 KB |
Output is correct |
36 |
Correct |
115 ms |
15064 KB |
Output is correct |
37 |
Correct |
122 ms |
15628 KB |
Output is correct |
38 |
Correct |
120 ms |
15308 KB |
Output is correct |
39 |
Correct |
113 ms |
14368 KB |
Output is correct |
40 |
Correct |
118 ms |
14400 KB |
Output is correct |
41 |
Correct |
115 ms |
14428 KB |
Output is correct |
42 |
Correct |
132 ms |
14384 KB |
Output is correct |
43 |
Correct |
115 ms |
14280 KB |
Output is correct |
44 |
Correct |
115 ms |
13968 KB |
Output is correct |
45 |
Correct |
113 ms |
14020 KB |
Output is correct |
46 |
Correct |
122 ms |
14112 KB |
Output is correct |
47 |
Correct |
117 ms |
14124 KB |
Output is correct |
48 |
Correct |
111 ms |
14044 KB |
Output is correct |
49 |
Correct |
116 ms |
14700 KB |
Output is correct |
50 |
Correct |
120 ms |
14712 KB |
Output is correct |
51 |
Correct |
122 ms |
14660 KB |
Output is correct |
52 |
Correct |
116 ms |
14728 KB |
Output is correct |
53 |
Correct |
115 ms |
14656 KB |
Output is correct |