Submission #674946

#TimeUsernameProblemLanguageResultExecution timeMemory
674946bashkort벽 (IOI14_wall)C++17
100 / 100
711 ms69492 KiB
#include "wall.h"
#include <bits/stdc++.h>

using namespace std;

constexpr int inf = 1e9 + 7;

struct Info {
    int L = 0, R = inf;
    Info(int x, int y) : L(x), R(y) {}
    Info() = default;
};

void apply(Info &a, Info b) {
    if (a.L >= b.R) {
        a.L = a.R = b.R;
    } else if (a.R <= b.L) {
        a.L = a.R = b.L;
    } else {
        a.L = max(a.L, b.L);
        a.R = min(a.R, b.R);
    }
}

vector<Info> t;

int sz = 1;
void init(int n) {
    sz = 1 << __lg(n) + bool(n & (n - 1));
    t.assign(sz << 1, {});
}

void apply(int x, Info b) {
    apply(t[x], b);
}

void push(int x) {
    apply(x << 1, t[x]);
    apply(x << 1 | 1, t[x]);
    t[x] = Info();
}

void rangeApply(int l, int r, Info info, int x = 1, int lx = 0, int rx = sz) {
    if (l >= rx || lx >= r) {
        return;
    }
    if (l <= lx && rx <= r) {
        apply(x, info);
        return;
    }
    push(x);
    int mid = (lx + rx) >> 1;
    rangeApply(l, r, info, x << 1, lx, mid);
    rangeApply(l, r, info, x << 1 | 1, mid, rx);
}

void buildWall(int n, int k, int op[], int left[], int right[], int height[], int finalHeight[]) {
    init(n);
    for (int i = 0; i < k; ++i) {
        Info info{};
        if (op[i] == 1) {
            info.L = height[i];
        } else {
            info.R = height[i];
        }
        rangeApply(left[i], right[i] + 1, info);
    }
    for (int i = 0; i < n; ++i) {
        Info info(0, 0);
        int x = i + sz;
        while (x > 0) {
            apply(info, t[x]);
            x >>= 1;
        }
        finalHeight[i] = info.L;
    }
}

Compilation message (stderr)

wall.cpp: In function 'void init(int)':
wall.cpp:29:23: warning: suggest parentheses around '+' inside '<<' [-Wparentheses]
   29 |     sz = 1 << __lg(n) + bool(n & (n - 1));
      |               ~~~~~~~~^~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...