#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
struct func{
int poz;
int h;
};
int f(func x,int i)
{
double sol1=x.h+(double)sqrt((double)abs(i-x.poz));
int sol=sol1;
if(sol<sol1)
sol++;
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);
}
}
int 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++)
{
int d=ST.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:60:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%i",&n);
~~~~~^~~~~~~~~
pio.cpp:65:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%i",&h[i]);
~~~~~^~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
348 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
552 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
38 ms |
1884 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
58 ms |
2704 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
86 ms |
3140 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
137 ms |
4572 KB |
Output is correct |
2 |
Incorrect |
127 ms |
4572 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
291 ms |
9716 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
488 ms |
16372 KB |
Output is correct |
2 |
Incorrect |
494 ms |
16372 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
707 ms |
23064 KB |
Output is correct |
2 |
Incorrect |
664 ms |
23064 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
656 ms |
23064 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |