답안 #199244

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
199244 2020-01-30T15:32:22 Z wet_water 새 집 (APIO18_new_home) C++14
컴파일 오류
0 ms 0 KB
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>

#define MAX_N 300005
#define f first
#define s second

using namespace std;

typedef pair<int, int> ii;
typedef pair<int, ii> pii;

class SegTree {
    private:
        ii tree[4 * MAX_N];
        multiset<int> c[4 * MAX_N];

    public:
        SegTree(int N) {

        }

        ii cmb(ii a, ii b) {
            if (a.f == -1)
                return (a);
            if (b.f == -1)
                return (b);

            return (ii(max(a.f, b.f), min(a.s, b.s)));
        }

        ii get_val(int l, int r, int a, int b, int ind) {
            if (a <= l && r <= b) { return (tree[ind]); }
            if (a > r || b < l) { return (ii(0, 1000000000)); }

            ii leftS = get_val(l, (l + r) / 2, a, b, 2 * ind);
            ii rightS = get_val((l + r) / 2 + 1, r, a, b, 2 * ind + 1);

            return (cmb(leftS, rightS));
        }

        ii query(int a, int b)
        { return (get_val(0, MAX_N, a, b, 1)); }

        void change_val(int l, int r, int newVal, int ind, int tmp) {
            if (tmp > r || tmp < l) { return; }
            if (l == r) {
                if (newVal > 0) {
                    c[ind].insert(newVal);
                    tree[ind].f = *c[ind].rbegin();
                    tree[ind].s = *c[ind].begin();
                } else {
                    if (c.find(-newVal) != c.end()))
                        c[ind].erase(c[ind].find(-newVal));

                    if (c[ind].empty()) {
                        tree[ind].f = -1;
                        tree[ind].s = -1;
                    } else {
                        tree[ind].f = *c[ind].rbegin();
                        tree[ind].s = *c[ind].begin();
                    }
                }

                return;
            }

            change_val(l, (r + l) / 2, newVal, 2 * ind, tmp);
            change_val((r + l) / 2 + 1, r, newVal, 2 * ind + 1, tmp);

            tree[ind] = cmb(tree[2 * ind], tree[2 * ind + 1]);
        }

        void update(int ind, int val)
        { change_val(0, MAX_N, val, 1, ind); }
};

int ans[MAX_N];
int N, K, Q;

bool cmp(pii a, pii b) {
    return (abs(a.f) < abs(b.f));
}

int main() {
    cin >> N >> K >> Q;

    vector<pii> events;

    int a, b, c, d;
    for (int i = 0; i < N; i ++) {
        cin >> a >> b >> c >> d;
        events.push_back(pii(c, ii(a, b)));
        events.push_back(pii(-(d + 1), ii(a, b)));
    }

    sort(events.begin(), events.end(), cmp);

    SegTree seg(MAX_N);

    vector<pii> query (Q);
    for (int i = 0; i < Q; i ++) {
        cin >> query[i].s.f >> query[i].f;
        query[i].s.s = i;
    }

    sort(query.begin(), query.end());

    int lft = 0;
    for (int i = 0; i < Q; i ++) {
        while (abs(events[lft].f) <= query[i].f) {
            if (events[lft].f > 0) {
                seg.update(events[lft].s.s, events[lft].s.f);
            } else {
                seg.update(events[lft].s.s, -events[lft].s.f);
            }

            lft ++;
        }

        ii cur = seg.query(1, K);

        if (cur.f == -1) {
            ans[query[i].s.s] = -1;
        } else {
            ans[query[i].s.s] = max(abs(query[i].s.f - cur.f), abs(query[i].s.f - cur.s));
        }
    }

    for (int i = 0; i < Q; i ++)
        cout << ans[i] << endl;

    return (0);
}

Compilation message

new_home.cpp: In member function 'void SegTree::change_val(int, int, int, int, int)':
new_home.cpp:55:27: error: request for member 'find' in '((SegTree*)this)->SegTree::c', which is of non-class type 'std::multiset<int> [1200020]'
                     if (c.find(-newVal) != c.end()))
                           ^~~~
new_home.cpp:55:46: error: request for member 'end' in '((SegTree*)this)->SegTree::c', which is of non-class type 'std::multiset<int> [1200020]'
                     if (c.find(-newVal) != c.end()))
                                              ^~~
new_home.cpp:55:52: error: expected primary-expression before ')' token
                     if (c.find(-newVal) != c.end()))
                                                    ^