#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=x.h+(double)sqrt((double)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);
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;
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=0;i<n;i++)
{
double d=ST.get(i);
int a=d;
if(d>a)
a++;
printf("%i\n",a-h[i]);
}
return 0;
}
Compilation message
pio.cpp: In function 'int main()':
pio.cpp:57:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%i",&n);
~~~~~^~~~~~~~~
pio.cpp:62: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 |
3 ms |
376 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
508 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
508 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
31 ms |
1720 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
54 ms |
2680 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
63 ms |
3084 KB |
Output is correct |
2 |
Correct |
59 ms |
3084 KB |
Output is correct |
3 |
Incorrect |
62 ms |
3276 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
98 ms |
4448 KB |
Output is correct |
2 |
Correct |
95 ms |
4448 KB |
Output is correct |
3 |
Incorrect |
98 ms |
4996 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
238 ms |
9696 KB |
Output is correct |
2 |
Correct |
229 ms |
9696 KB |
Output is correct |
3 |
Incorrect |
244 ms |
10116 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
411 ms |
16392 KB |
Output is correct |
2 |
Correct |
368 ms |
16392 KB |
Output is correct |
3 |
Incorrect |
386 ms |
16392 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
556 ms |
23060 KB |
Output is correct |
2 |
Correct |
522 ms |
23060 KB |
Output is correct |
3 |
Incorrect |
529 ms |
23184 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
604 ms |
23184 KB |
Output is correct |
2 |
Correct |
524 ms |
23184 KB |
Output is correct |
3 |
Incorrect |
529 ms |
23184 KB |
Output isn't correct |