#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(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 |
2 ms |
256 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
504 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
552 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
37 ms |
2216 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
55 ms |
3696 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
64 ms |
4768 KB |
Output is correct |
2 |
Correct |
58 ms |
4888 KB |
Output is correct |
3 |
Incorrect |
62 ms |
5532 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
98 ms |
7480 KB |
Output is correct |
2 |
Correct |
95 ms |
8424 KB |
Output is correct |
3 |
Incorrect |
99 ms |
9524 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
242 ms |
16532 KB |
Output is correct |
2 |
Correct |
231 ms |
18300 KB |
Output is correct |
3 |
Incorrect |
237 ms |
20356 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
387 ms |
30036 KB |
Output is correct |
2 |
Correct |
371 ms |
31332 KB |
Output is correct |
3 |
Incorrect |
373 ms |
35520 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
553 ms |
46952 KB |
Output is correct |
2 |
Correct |
536 ms |
48964 KB |
Output is correct |
3 |
Incorrect |
543 ms |
54884 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
568 ms |
57228 KB |
Output is correct |
2 |
Correct |
524 ms |
61648 KB |
Output is correct |
3 |
Runtime error |
540 ms |
66560 KB |
Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience. |