#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
struct func{
int poz;
int h;
};
double f(func x,int i,int p)
{
if(p==0)
{
if(i>x.poz)
return -1;
}
else
if(i<x.poz)
return -1;
double sol=(double)x.h+(double)sqrt(abs(i-x.poz));
return sol;
}
int N;
struct liChao{
vector<func> tr;
void init(func start)
{
tr.resize(4*N);
fill(tr.begin(),tr.end(),start);
}
void set(func x,int p,int i=1,int l=0,int r=N)
{
int m=(l+r)>>1;
if(m>p)
{
set(x,p,2*i,l,m);
return;
}
bool lft=f(x,l,0)>f(tr[i],l,0);
bool mid=f(x,m,0)>f(tr[i],m,0);
if(mid){
swap(tr[i],x);
}
if(r-l==1)
return;
if(lft!=mid)
{
set(x,p,2*i,l,m);
}
else
{
set(x,p,2*i+1,m,r);
}
}
double get(int poz,int i=1,int l=0,int r=N)
{
int m=(l+r)>>1;
if(r-l==1)
return f(tr[i],poz,0);
if(poz<m)
return max(f(tr[i],poz,0),get(poz,2*i,l,m));
else
return max(f(tr[i],poz,0),get(poz,2*i+1,m,r));
}
} ST;
struct liChao2{
vector<func> tr;
void init(func start)
{
tr.resize(4*N);
fill(tr.begin(),tr.end(),start);
}
void set(func x,int p,int i=1,int l=0,int r=N)
{
int m=(l+r)>>1;
if(m<p)
{
//printf("Usao\n");
if(r-l==1)
return;
set(x,p,2*i+1,m,r);
return;
}
//printf("%i %i %i %i %i %i %i %i\n",x.h,x.poz,p,i,l,r,tr[i].h,tr[i].poz);
bool lft=f(x,l,1)>f(tr[i],l,1);
bool mid=f(x,m,1)>f(tr[i],m,1);
if(mid){
swap(tr[i],x);
}
if(r-l==1)
return;
if(lft!=mid)
{
set(x,p,2*i,l,m);
}
else
{
set(x,p,2*i+1,m,r);
}
}
double get(int poz,int i=1,int l=0,int r=N)
{
int m=(l+r)>>1;
if(r-l==1)
return f(tr[i],poz,1);
if(poz<m)
return max(f(tr[i],poz,1),get(poz,2*i,l,m));
else
return max(f(tr[i],poz,1),get(poz,2*i+1,m,r));
}
} ST2;
int main()
{
int n;
scanf("%i",&n);
N=n;
vector<int> h(n);
for(int i=0;i<n;i++)
{
scanf("%i",&h[i]);
func tr;
tr.h=h[i];
tr.poz=i;
if(i==0)
ST2.init(tr);
else
ST2.set(tr,i);
}
for(int i=n-1;i>=0;i--)
{
func tr;
tr.h=h[i];
tr.poz=i;
if(i==n-1)
ST.init(tr);
else
ST.set(tr,i);
}
for(int i=0;i<n;i++)
{
double d=max(ST.get(i),ST2.get(i));
//printf("%i: %f\n",i,d);
int a=d;
//printf("%i\n",a);
if(d>a)
a++;
printf("%i\n",a-h[i]);
}
return 0;
}
Compilation message
pio.cpp: In function 'int main()':
pio.cpp:117:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%i",&n);
~~~~~^~~~~~~~~
pio.cpp:122:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%i",&h[i]);
~~~~~^~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
508 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
508 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
44 ms |
2796 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
85 ms |
4412 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
77 ms |
5236 KB |
Output is correct |
2 |
Correct |
74 ms |
5236 KB |
Output is correct |
3 |
Correct |
78 ms |
5388 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
144 ms |
7656 KB |
Output is correct |
2 |
Correct |
114 ms |
7656 KB |
Output is correct |
3 |
Correct |
117 ms |
8092 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
298 ms |
16908 KB |
Output is correct |
2 |
Correct |
284 ms |
16908 KB |
Output is correct |
3 |
Correct |
311 ms |
17420 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
471 ms |
27396 KB |
Output is correct |
2 |
Correct |
445 ms |
27396 KB |
Output is correct |
3 |
Correct |
476 ms |
27476 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
705 ms |
38756 KB |
Output is correct |
2 |
Correct |
639 ms |
38756 KB |
Output is correct |
3 |
Correct |
673 ms |
38888 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
727 ms |
38888 KB |
Output is correct |
2 |
Correct |
674 ms |
38888 KB |
Output is correct |
3 |
Correct |
641 ms |
38888 KB |
Output is correct |