답안 #1111116

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1111116 2024-11-11T14:16:44 Z TheGreatAntivirus 벽 (IOI14_wall) C++17
컴파일 오류
0 ms 0 KB
#include "wall.h"
#include <bits/stdc++.h>

using namespace std;

struct query
{
    int mx, mn;
    query()
    {
        mx = 0; mn = 1e9;
    }
};

class segment
{
    public:
        void push(int v, int vl, int vr)
        {
            if(vl != vr)
            {
                sg[2 * v].mx = min(sg[v].mn, max(sg[v].mx, sg[2 * v].mx));
                sg[2 * v + 1].mx = min(sg[v].mn, max(sg[v].mx, sg[2 * v + 1].mx));
                sg[2 * v].mn = max(sg[v].mx, min(sg[v].mn, sg[2 * v].mn));
                sg[2 * v + 1].mn = max(sg[v].mx, min(sg[v].mn, sg[2 * v + 1].mn));
                sg[v].mn = 1e9;
                sg[v].mx = 0;
            }
        }
        void upd(int v, int vl, int vr, int l, int r, int val, int m)
        {
            if(vl > r || vr < l)
            {
                return;
            }
            push(v, vl, vr);
            if(l <= vl && vr <= r)
            {
                if(m == 1)
                {
                    sg[v].mx = max(sg[v].mx, val);
                    sg[v].mn = max(sg[v].mn, sg[v].mx);
                }
                else
                {
                    sg[v].mn = min(sg[v].mn, val);
                    sg[v].mx = min(sg[v].mx, sg[v].mn);
                }
                push(v, vl, vr);
                return;
            }
            int mid = (vl + vr) / 2;
            upd(2 * v, vl, mid, l, r, val, m);
            upd(2 * v + 1, mid + 1, vr, l, r, val, m);
        }
        query get(int v, int vl, int vr, int p)
        {
            if(vl > p || vr < p)
            {
                query tmp;
                return tmp;
            }
            push(v, vl, vr);
            if(vl == vr && vl == p)
            {
                return sg[v];
            }
            int mid = (vl + vr) / 2;
            query lc = get(2 * v, vl, mid, p),
                  rc = get(2 * v + 1, mid + 1, vr, p);
            query res; res.mn = min(lc.mn, rc.mn);
            res.mx = max(lc.mx, rc.mx);
            return res;
        }
};

void buildWall(int n, int k, int op[], int left[], int right[], int height[], int finalHeight[])
{
	segment s;
    for(int i = 0; i < k; i++)
    {
        s.upd(1, 0, MAXN - 1, left[i], right[i], height[i], op[i]);
    }
    for(int i = 0; i < n; i++)
    {
        query ans = s.get(1, 0, MAXN - 1, i);
        finalHeight[i] = min(ans.mx, ans.mn);
    }
}

Compilation message

wall.cpp: In member function 'void segment::push(int, int, int)':
wall.cpp:22:17: error: 'sg' was not declared in this scope
   22 |                 sg[2 * v].mx = min(sg[v].mn, max(sg[v].mx, sg[2 * v].mx));
      |                 ^~
wall.cpp: In member function 'void segment::upd(int, int, int, int, int, int, int)':
wall.cpp:41:21: error: 'sg' was not declared in this scope
   41 |                     sg[v].mx = max(sg[v].mx, val);
      |                     ^~
wall.cpp:46:21: error: 'sg' was not declared in this scope
   46 |                     sg[v].mn = min(sg[v].mn, val);
      |                     ^~
wall.cpp: In member function 'query segment::get(int, int, int, int)':
wall.cpp:66:24: error: 'sg' was not declared in this scope
   66 |                 return sg[v];
      |                        ^~
wall.cpp: In function 'void buildWall(int, int, int*, int*, int*, int*, int*)':
wall.cpp:82:21: error: 'MAXN' was not declared in this scope
   82 |         s.upd(1, 0, MAXN - 1, left[i], right[i], height[i], op[i]);
      |                     ^~~~
wall.cpp:86:33: error: 'MAXN' was not declared in this scope
   86 |         query ans = s.get(1, 0, MAXN - 1, i);
      |                                 ^~~~