답안 #1006295

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1006295 2024-06-23T17:00:16 Z jer033 벽 (IOI14_wall) C++17
컴파일 오류
0 ms 0 KB
#include <bits/stdc++.h>
#include "wall.h"
using namespace std;

class SegTree{
public:
    int left_index;
    int right_index;
    int lo_value;
    int hi_value;
    SegTree* left_child;
    SegTree* right_child;
    SegTree* parent;

    SegTree(int l, int r, SegTree* magulang)
    {
        parent = magulang;
        left_index = l;
        right_index = r;
        lo_value = 0;
        hi_value = 0;
        if (l==r)
        {
            left_child = nullptr;
            right_child = nullptr;
        }
        else
        {
            int m = (l+r)/2;
            left_child = &SegTree(l, m, this);
            right_child = &SegTree(m+1, r, this);
        }
    }

    SegTree(int n)
    {
        SegTree(0, n-1, nullptr);
    }

    void update_self()
    {
        if (hi_value < parent->lo_value)
        {
            lo_value = parent->lo_value;
            hi_value = parent->lo_value;
        }
        else if (lo_value > parent->hi_value)
        {
            lo_value = parent->hi_value;
            hi_value = parent->hi_value;
        }
        else
        {
            lo_value = max(lo_value, parent->lo_value);
            hi_value = min(hi_value, parent->hi_value);
        }
    }

    void update_children()
    {
        if (left_child!=nullptr)
        {
            left_child->update_self();
            right_child->update_self();
        }
    }

    void grab_new_info()
    {
        if (left_child!=nullptr)
        {
            lo_value = min(left_child->lo_value, right_child->lo_value);
            hi_value = max(left_child->hi_value, right_child->hi_value);
        }
        if (parent!=nullptr)
            parent->grab_new_info();
    }

    void modify_self(int typ, int h)
    {
        if (typ==1)
        {
            lo_value = h;
            if (hi_value < h)
                hi_value = h;
        }
        else
        {
            hi_value = h;
            if (lo_value > h)
                lo_value = h;
        }
    }

    void builder(int typ, int l, int r, int h)
    {
        update_children();
        int mid_index = (left_index+right_index)/2;
        if ((l==left_index) and (r==right_index))
        {
            modify_self(typ, h);
            grab_new_info();
        }
        else
        {
            if (l<=mid_index)
                left_child->builder(typ, l, mid_index, h);
            if (r>=(mid_index+1))
                right_child->builder(typ, mid_index+1, r, h);
        }
    }

    void answer(int finalHeight[])
    {
        if (left_index == right_index)
        {
            finalHeight[left_index] = lo_value;
        }
        else
        {
            update_children();
            left_child->answer(finalHeight);
            right_child->answer(finalHeight);
        }
    }
};

void buildWall(int n, int k, int op[], int left[], int right[], int height[], int finalHeight[])
{
   SegTree* seg = new SegTree(n);
    for (int oper = 0; oper<k; oper++)
    {
        int typ = op[oper];
        int l = left[oper];
        int r = right[oper];
        int h = height[oper];
        seg->builder(typ, l, r, h);
    }
    seg->answer(finalHeight);
}

Compilation message

wall.cpp: In constructor 'SegTree::SegTree(int, int, SegTree*)':
wall.cpp:30:27: error: taking address of rvalue [-fpermissive]
   30 |             left_child = &SegTree(l, m, this);
      |                           ^~~~~~~~~~~~~~~~~~~
wall.cpp:31:28: error: taking address of rvalue [-fpermissive]
   31 |             right_child = &SegTree(m+1, r, this);
      |                            ^~~~~~~~~~~~~~~~~~~~~