#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)
{
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 i=1,int l=0,int r=N)
{
int m=(l+r)>>1;
bool lft=f(x,l)>f(tr[i],l);
bool mid=f(x,m)>f(tr[i],m);
//printf("%i %i, %i %i %i %i %i %i\n",x.h,x.poz,i,l,r,m,lft,mid);
if(mid){
swap(tr[i],x);
}
if(r-l==1)
return;
if(lft!=mid)
{
set(x,2*i,l,m);
}
else
{
set(x,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);
if(poz<m)
return max(f(tr[i],poz),get(poz,2*i,l,m));
else
return max(f(tr[i],poz),get(poz,2*i+1,m,r));
}
} ST,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)
ST.init(tr);
else
ST.set(tr);
}
for(int i=n-1;i>=0;i--)
{
func tr;
tr.h=h[i];
tr.poz=i;
if(i==n-1)
ST2.init(tr);
else
ST2.set(tr);
}
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:58:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%i",&n);
~~~~~^~~~~~~~~
pio.cpp:63: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 |
Incorrect |
2 ms |
256 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
500 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
500 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
41 ms |
2792 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
69 ms |
4372 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
90 ms |
5208 KB |
Output is correct |
2 |
Correct |
88 ms |
5208 KB |
Output is correct |
3 |
Incorrect |
96 ms |
5476 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
138 ms |
7536 KB |
Output is correct |
2 |
Correct |
153 ms |
7724 KB |
Output is correct |
3 |
Incorrect |
140 ms |
8104 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
341 ms |
16940 KB |
Output is correct |
2 |
Correct |
336 ms |
16940 KB |
Output is correct |
3 |
Incorrect |
333 ms |
17452 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
551 ms |
27428 KB |
Output is correct |
2 |
Correct |
544 ms |
27428 KB |
Output is correct |
3 |
Incorrect |
525 ms |
27540 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
805 ms |
38828 KB |
Output is correct |
2 |
Correct |
789 ms |
38828 KB |
Output is correct |
3 |
Incorrect |
808 ms |
38828 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
765 ms |
38828 KB |
Output is correct |
2 |
Correct |
791 ms |
38828 KB |
Output is correct |
3 |
Incorrect |
797 ms |
38828 KB |
Output isn't correct |