Submission #47372

# Submission time Handle Problem Language Result Execution time Memory
47372 2018-05-01T18:28:08 Z nickyrio Lightning Conductor (POI11_pio) C++17
Compilation error
0 ms 0 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;
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) 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
}

Compilation message

pio.cpp: In function 'int main()':
pio.cpp:40:15: error: 'lg' was not declared in this scope
     FOR(j, 1, lg[n] + 1) {
               ^
pio.cpp:3:46: note: in definition of macro 'FOR'
 #define FOR(i, a, b) for (int i = (a); i <= (b); ++i)
                                              ^
pio.cpp:40:15: note: suggested alternative: 'log'
     FOR(j, 1, lg[n] + 1) {
               ^
pio.cpp:3:46: note: in definition of macro 'FOR'
 #define FOR(i, a, b) for (int i = (a); i <= (b); ++i)
                                              ^
pio.cpp:60:15: error: 'lg' was not declared in this scope
     FOR(j, 1, lg[n] + 1) {
               ^
pio.cpp:3:46: note: in definition of macro 'FOR'
 #define FOR(i, a, b) for (int i = (a); i <= (b); ++i)
                                              ^
pio.cpp:60:15: note: suggested alternative: 'log'
     FOR(j, 1, lg[n] + 1) {
               ^
pio.cpp:3:46: note: in definition of macro 'FOR'
 #define FOR(i, a, b) for (int i = (a); i <= (b); ++i)
                                              ^