# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
40945 | wzy | Lightning Conductor (POI11_pio) | C++11 | 188 ms | 57664 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <stdio.h>
#include <vector>
#include <stdint.h>
#include <math.h>
#include <iostream>
#define int long long
#define eps (int) 1e9
#define pb push_back
using namespace std;
int n , v[500003] , ans[500003];
struct line{
int a , b;
double value(int x){
return sqrt(x + a)+b;
}
};
int ponteiro = 0;
vector<line> cht;
int intersect(line i, line j){
int l =- (int) min(i.a , j.a) , r = (int) 1e9;
while(l <= r){
int mid = (l+r);
mid = floor(mid / 2.00);
double curr = i.value(mid ) - j.value(mid );
if(curr > 0){
l = mid + 1;
}
else r = mid - 1;
}
return l;
}
void add_line(line x){
while(cht.size() && cht.back().value(-x.a) < x.b && cht.back().value((int) 1e9) < x.value((int) 1e9)) cht.pop_back();
if(cht.size() && cht.back().value(-x.a) >= x.b && cht.back().value((int) 1e9) >= x.value((int) 1e9)) return;
while(cht.size() >= 2 && intersect(cht[(int)cht.size() - 1] , x) <= intersect(cht[(int) cht.size() - 2] , cht.back())) cht.pop_back();
cht.pb(x);
}
int query(int x){
ponteiro = min(ponteiro , (int)cht.size() - 1);
for(int i = ponteiro ; i < (int) cht.size() - 1 ; i ++){
if(cht[i].value(x) > cht[i+1].value(x)) break;
ponteiro++;
}
return ceil(cht[ponteiro].value(x)*1.000);
}
int32_t main(){
scanf("%lld" , &n);
for(int i = 1 ; i<=n;i++) scanf("%lld" , &v[i]);
for(int i = 1 ; i <= n;i++){
add_line({-i ,v[i]});
ans[i] = query(i);
}
cht.clear();
ponteiro = 0;
for(int i = n ; i >= 1 ; i--){
add_line({i , v[i]});
ans[i] = max(ans[i] , query(-i));
}
for(int i = 1 ; i <= n;i++){
printf("%lld\n" , ans[i] - v[i]);
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |