답안 #1007671

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1007671 2024-06-25T10:02:40 Z farrellw 벽 (IOI14_wall) C++14
컴파일 오류
0 ms 0 KB
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define INF 100005
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
 
#include "wall.h"
 
ii combine(ii upd_new, ii upd_old) {    // apply upd_new to upd_old
    ii res = {max(upd_new.fi, upd_old.fi), min(upd_new.se, upd_old.se)};
    if (res.fi > res.se) { // The ranges are disjoint, so suffices to check either
        return (upd_old.se < upd_new.se) ? make_pair(upd_new.fi, upd_new.fi) : make_pair(upd_new.se, upd_new.se);
    }
    return res;
}
 
struct Segtree {    // Segtree of updates
    int sz;
    vector<ii> upd;    // store (a, b)
    vi left;
    vi right;
    vi mid;
    Segtree(int N) {
        sz = 1;
        while (sz < N)
            sz *= 2;
        upd = vii(2 * sz, {0, INF});
        left = vi(2 * sz, 0);
        right = vi(2 * sz, 0);
        mid = vi(2 * sz, 0);
        for(int id = sz-1; id < 2*sz-1; id++) {
            left[id] = id-sz+1;
            right[id] = id-sz+2;
        }
        for(int id = sz-2; id >= 0; id--) {
            left[id] = left[(id<<1)|1];
            right[id] = right[2 * id + 2];
            mid[id] = (left[id] + right[id])>>1;
        }
    }
    void push(int id) { // O(1), for regular updates
        if (mid[id]) {
            upd[(id<<1)|1] = combine(upd[id], upd[(id<<1)|1]);
            upd[2 * id + 2] = combine(upd[id], upd[2 * id + 2]);
            upd[id] = {0, INF};
        }
    }
 
    void push_recursive(int id) { // O(N), only for answer extraction at the end
        if(mid[id]) {
            push(id);
            push_recursive((id<<1)|1);
            push_recursive(2 * id + 2);
        }
    }
 
    void range_upd(int qleft, int qright, ii val, int id) {
        if (qleft <= left[id] && right[id] <= qright) {
            upd[id] = combine(val, upd[id]);
            return;
        }
        if (qright <= left[id] || right[id] <= qleft)
            return;
        push(id);
        range_upd(qleft, qright, val, (id<<1)|1);
        range_upd(qleft, qright, val, 2 * id + 2);
    }
    void range_upd(int qleft, int qright, ii val) {
        range_upd(qleft, qright, val, 0);
    }
};
 
void buildWall(int n, int k, int op[], int left[], int right[], int height[], int finalHeight[]) {
    Segtree tree(n);
    for(int z = 0; z < k; z++) {
        ii upd_val = (op[z] == 1) ? make_pair(height[z], INF) : make_pair(0, height[z]);
        tree.range_upd(left[z], right[z]+1, upd_val);
    }
    tree.push_recursive(0, 0, tree.sz);
    for(int z = 0; z < n; z++) {
        finalHeight[z] = tree.upd[z+tree.sz-1].fi;
    }
    return;
}

Compilation message

wall.cpp: In function 'void buildWall(int, int, int*, int*, int*, int*, int*)':
wall.cpp:82:38: error: no matching function for call to 'Segtree::push_recursive(int, int, int&)'
   82 |     tree.push_recursive(0, 0, tree.sz);
      |                                      ^
wall.cpp:52:10: note: candidate: 'void Segtree::push_recursive(int)'
   52 |     void push_recursive(int id) { // O(N), only for answer extraction at the end
      |          ^~~~~~~~~~~~~~
wall.cpp:52:10: note:   candidate expects 1 argument, 3 provided