Submission #248668

# Submission time Handle Problem Language Result Execution time Memory
248668 2020-07-13T03:49:44 Z thecodingwizard Lightning Conductor (POI11_pio) C++11
36 / 100
145 ms 15224 KB
#include <bits/stdc++.h>

using namespace std;

const int inf = 1e9+10;

struct func {
    int h, i, l, r;
};

int n; 
int mx[500000];
int mx2[500000];
int H[500000];
int Sqrt[500000];

int eval(func f, int i) {
    return f.h+Sqrt[abs(i-f.i)];
    assert(i>=f.i);
    return f.h+Sqrt[i-f.i];
}

// returns when right part of func a intersects func b
int intersectRight(func a, func b) {
    if (eval(a, n-1) >= eval(b, n-1)) return inf;
    long long d = b.h-a.h;
    if (b.i-a.i-d*d<0) return -1;
    long double x = (b.i-a.i)/2.0/d-d/2.0;
    long long ans = ceil(x*x)+b.i;
    assert(ans < n && ans >= 0);
    return ans;
}

void solveRight(int mx[]) {
    vector<func> s;
    for (int i = 0; i < n; i++) {
        func f = {H[i], i, 0, n-1};
        while (!s.empty()) {
            if (s.size()>=2) {
                func f2 = s[s.size()-2];
                int intersect = intersectRight(f2, f);
                if (intersect <= f2.l || intersect < n) {
                    s.pop_back();
                    continue;
                }
            }
            func f2 = s.back();
            int intersect = intersectRight(f2, f);
            //cout << f2.i << " intersects " << f.i << " at " << intersect << endl;
            if (intersect <= f2.l) {
                s.pop_back();
                /*
                s.top().r = f.l-1;
                break;
                */
            } else {
                if (intersect - 1 <= n-1) s.back().r = intersect - 1;
                f.l = intersect;
                break;
            }
        }
        if (f.l <= n-1) s.push_back(f);
        //assert(f.l >= i);
    }
    while (!s.empty()) {
        func f = s.back(); s.pop_back();
        //cout << f.i << " is max from " << f.l << " to " << f.r << endl;
        for (int i = max(f.l,0); i <= f.r; i++) mx[i] = max(mx[i], eval(f, i));
    }
    for (int i = 0; i < n; i++) {
        //cout << "mx[" << i << "] = " << mx[i] << endl;
    }
}

int main() {
    cin.tie(0); ios_base::sync_with_stdio(0);
    cin >> n;
    Sqrt[0] = 0;
    for (int i = 1; i <= 1000; i++) {
        for (int j = (i-1)*(i-1)+1; j <= min(i*i, n-1); j++) Sqrt[j] = i;
    }
    for (int i = 0; i < n; i++) {
        cin >> H[i]; mx[i] = 0;
    }
    solveRight(mx);
    for (int i = 0; i < n/2; i++) {
        swap(H[i], H[n-i-1]);
    }
    solveRight(mx2);
    for (int i = 0; i < n; i++) {
        mx[i] = max(mx[i], mx2[n-1-i]);
    }
    for (int i = 0; i < n/2; i++) {
        swap(H[i], H[n-i-1]);
    }
    for (int i = 0; i < n; i++) {
        cout << mx[i]-H[i] << "\n";
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 384 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 1440 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 2176 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 20 ms 2300 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 27 ms 3328 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 67 ms 6136 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 100 ms 11256 KB Output is correct
2 Correct 97 ms 9208 KB Output is correct
3 Incorrect 103 ms 10352 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 141 ms 15224 KB Output is correct
2 Incorrect 136 ms 12164 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 145 ms 12664 KB Output isn't correct
2 Halted 0 ms 0 KB -