Submission #47373

# Submission time Handle Problem Language Result Execution time Memory
47373 2018-05-01T18:28:41 Z nickyrio Lightning Conductor (POI11_pio) C++17
0 / 100
345 ms 24980 KB
//https://oj.uz/problem/view/POI11_pio
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i <= (b); ++i)
#define FORD(i, a, b) for (int i = (a); i >= (b); --i)
#define REP(i, a) for (int i = 0; i < (a); ++i)
#define DEBUG(x) { cerr << #x << '=' << x << endl; }
#define Arr(a, l, r) { cerr << #a << " = {"; FOR(_, l, r) cerr << ' ' << a[_]; cerr << "}\n"; }
#define N 500100
#define pp pair<int, int>
#define endl '\n'
#define IO ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define taskname ""
#define bit(S, i) (((S) >> (i)) & 1)
using namespace std;

int n, lg[N];
long long h[N], MAX[N][2];

int d, stop[N];
long long need[N];
long long Get(int l, int r) {
    return max(MAX[l][d], MAX[r - (1 << d) + 1][d]);
}

int main() {
    #ifdef NERO
    //freopen("test.inp","r",stdin);
    //freopen("test.out","w",stdout);
    double stime = clock();
    #else
        //freopen(taskname".inp","r",stdin);
        //freopen(taskname".out","w",stdout);
    #endif //NERO
    IO;
    cin >> n;
    FOR(i, 1, n) lg[i] = log2(i);
    FOR(i, 1, n) cin >> h[i];
    // Update Right
    FOR(i, 1, n) MAX[i][0] = h[i], stop[i] = 0;
    d = 1;
    FOR(j, 1, lg[n] + 1) {
        d = 1 - d;
        FORD(i, n, 1) if (!stop[i]) {
            long long bef = min(1ll * n, 1ll * i + 1ll * (j - 1) * (j - 1));
            long long RIGHT = min(1ll * n, 1ll * i + 1ll * j * j);
            if (RIGHT <= bef) {
                MAX[i][1 - d] = MAX[i][d];
                stop[i] = 1;
                continue;
            }
            if (i + (1 << j) - 1 <= n) MAX[i][1 - d] = max(MAX[i][d], MAX[i + (1 << (j - 1))][d]);
            else MAX[i][1 - d] = MAX[i][d];
            need[i] = max(need[i], - h[i] + Get(bef + 1, RIGHT) + j);
            if (RIGHT == n) stop[i] = 1;
        } else MAX[i][1 - d] = MAX[i][d];
    }
    //Left
    reverse(h + 1, h + n + 1);
    FOR(i, 1, n) MAX[i][0] = h[i], stop[i] = 0, MAX[i][1] = 0;
    d = 1;
    FOR(j, 1, lg[n] + 1) {
        d = 1 - d;
        FORD(i, n, 1) if (!stop[i]) {
            long long bef = min(1ll * n, 1ll * i + 1ll * (j - 1) * (j - 1));
            long long RIGHT = min(1ll * n, 1ll * i + 1ll * j * j);
            if (RIGHT <= bef) {
                MAX[i][1 - d] = MAX[i][d];
                stop[i] = 1;
                continue;
            }
            if (i + (1 << j) - 1 <= n) MAX[i][1 - d] = max(MAX[i][d], MAX[i + (1 << (j - 1))][d]);
            else MAX[i][1 - d] = MAX[i][d];
            need[n - i + 1] = max(need[n - i + 1], - h[i] + Get(bef + 1, RIGHT) + j);
            if (RIGHT == n) stop[i] = 1;
        } else MAX[i][1 - d] = MAX[i][d];
    }
    FOR(i, 1, n) cout << need[i] << '\n';
    #ifdef NERO
    double etime = clock();
    cerr << "Execution time: " << (etime - stime) / CLOCKS_PER_SEC * 1000 << " ms.\n";
    #endif // NERO
}
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 376 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 488 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 544 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 15 ms 2000 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 25 ms 2960 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 30 ms 3360 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 45 ms 4836 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 106 ms 10508 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 174 ms 17808 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 345 ms 24980 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 263 ms 24980 KB Output isn't correct
2 Halted 0 ms 0 KB -