답안 #795611

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
795611 2023-07-27T11:42:28 Z chanhchuong123 벽 (IOI14_wall) C++14
컴파일 오류
0 ms 0 KB
#include "wall.h" 
#include <bits/stdc++.h>
using namespace std;
#define task ""
#define all(x) x.begin(), x.end()
#define FOR(i, a, b) for (int i = (a), _b = (b); i <= _b; ++i)
#define FORD(i, a, b) for (int i = (b), _a = (a); i >= _a; --i)

template <typename T1, typename T2> bool minimize(T1 &a, T2 b) {
	if (a > b) {a = b; return true;} return false;
}
template <typename T1, typename T2> bool maximize(T1 &a, T2 b) {
	if (a < b) {a = b; return true;} return false;
}

const int dx[] = {-1, 0, 0, +1};
const int dy[] = {0, -1, +1, 0};

const int INF = 1e9 + 7;
const int MAX = 2000002;
int n, h[MAX];
pair<int, int> st[MAX << 2];

void build(int id, int l, int r) {
    st[id] = {0, INF};
    if (l == r) {
        return;
    }
    int mid = l + r >> 1;
    build(id << 1, l, mid);
    build(id << 1 | 1, mid + 1, r);
}

void push(int id, int u, int d) {
    minimize(st[id].second, d);
    maximize(st[id].second, u);
    maximize(st[id].first, u);
    minimize(st[id].first, d);
}

void push(int id) {
    push(id << 1, st[id].first, st[id].second);
    push(id << 1 | 1, st[id].first, st[id].second);
    st[id] = {0, INF};
}

void update(int id, int l, int r, int u, int v, int newH, int t) {
    if (l > v || r < u) return;
    if (l >= u && r <= v) {
        if (t == 0) {
            maximize(st[id].second, newH);
            maximize(st[id].first, newH);
        } else {
            minimize(st[id].second, newH);
            minimize(st[id].first, newH);
        }
        return;
    }
    int mid = l + r >> 1; push(id);
    update(id << 1, l, mid, u, v, newH, t);
    update(id << 1 | 1, mid + 1, r, u, v, newH, t);
}

int get(int pos) {
    int id = 1, l = 1, r = n;
    while (l < r) {
        int mid = l + r >> 1; push(id);
        if (pos <= mid) id = id << 1, r = mid;
        else id = id << 1 | 1, l = mid + 1;
    }
    return min(st[id].first, st[id].second);
}

void prepare(int subtask, const vector<int> &height) {
    n = height.size();
    for (int i = 1; i <= n; ++i) {
        h[i] = height[i - 1];
    }
    build(1, 1, n);
}

void build_up(int l, int r, int t) { ++l; ++r;
    update(1, 1, n, l, r, t, 0);
}

void take_down(int l, int r, int t) { ++l; ++r;
    update(1, 1, n, l, r, t, 1);
}

int get_height(int i) { ++i;
    return get(i);
}

void buildWall(int N, int K, int op[], int left[], int right[], int height[], int finalHeight[]) {
    n = N;
    build(1, 1, n);
    for (int i = 0; i < k; ++i) {
        update(1, 1, n, left[i] + 1, right[i] + 1, height[i], op[i]);
    }
    for (int i = 0; i < n; ++i) {
        finalHeight[i] = get(i + 1);
    }
}

Compilation message

wall.cpp: In function 'void build(int, int, int)':
wall.cpp:29:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   29 |     int mid = l + r >> 1;
      |               ~~^~~
wall.cpp: In function 'void update(int, int, int, int, int, int, int)':
wall.cpp:59:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   59 |     int mid = l + r >> 1; push(id);
      |               ~~^~~
wall.cpp: In function 'int get(int)':
wall.cpp:67:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   67 |         int mid = l + r >> 1; push(id);
      |                   ~~^~~
wall.cpp: In function 'void buildWall(int, int, int*, int*, int*, int*, int*)':
wall.cpp:97:25: error: 'k' was not declared in this scope
   97 |     for (int i = 0; i < k; ++i) {
      |                         ^