답안 #849165

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
849165 2023-09-14T08:00:39 Z hngwlog 새 집 (APIO18_new_home) C++14
0 / 100
117 ms 22116 KB
    #include <bits/stdc++.h>
    using namespace std;
     
    #define fi first
    #define se second
    #define _size(x) (int)x.size()
    #define BIT(i, x) ((x >> i) & 1)
    #define MASK(n) ((1 << n) - 1)
    #define REP(i, n) for (int i = 0, _n = (n); i < _n; i++)
    #define FOR(i, a, b) for (int i = a, _b = (b); i <= _b; i++)
    #define FORD(i, a, b) for (int i = a, _b = (b); i >= _b; i--)
    #define FORB1(i, mask) for (int i = mask; i > 0; i ^= i & - i)
    #define FORB0(i, n, mask) for (int i = ((1 << n) - 1) ^ mask; i > 0; i ^= i & - i)
    #define FORALL(i, a) for (auto i: a)
    #define fastio ios_base::sync_with_stdio(0); cin.tie(0);
     
    struct storeNode {
     
        int x, t, a, b;
    };
     
    struct queryNode {
     
        int l, y, id;
    };
     
    int n, k, q;
    vector<storeNode> store;
    vector<queryNode> qu;
     
    namespace subtask12 {
     
        const int inf = 1e9;
     
        void main() {
     
            vector<pair<int, int>> g;
            FOR(i, 1, n) g.push_back({store[i].a, i}), g.push_back({store[i].b, - i});
            REP(i, q) g.push_back({qu[i].y, 0});
            sort(g.begin(), g.end(), [&] (const pair<int, int> a, pair<int, int> b) { return a.fi != b.fi ? a.fi < b.fi : a.se > b.se; });
            sort(qu.begin(), qu.end(), [&] (const queryNode a, queryNode b) { return a.y < b.y; });
            vector<int> ans(q);
            vector<multiset<int>> mts(k + 1);
            int i = 0, z = 0;
            while (i < _size(g)) {
                int j = i;
                while (j < _size(g) && g[j].fi == g[i].fi && g[j].se > 0) {
                    int id = g[j].se;
                    mts[store[id].t].insert(store[id].x);
                    j++;
                }
                while (j < _size(g) && g[j].fi == g[i].fi && g[j].se == 0) j++;
                while (z < q && qu[z].y == g[i].fi) {
                    int res = - 1;
                    FOR(id, 1, k) {
                        if (mts[id].empty()) {
                            res = - 1;
                            break;
                        }
                        auto it = mts[id].lower_bound(qu[z].l);
                        int _res = inf;
                        if (it != mts[id].end()) _res = min(_res, *it - qu[z].l);
                        if (it != mts[id].begin()) {
                            --it;
                            _res = max(_res, qu[z].l - *it);
                        }
                        res = max(res, _res);
                    }
                    ans[qu[z].id] = res;
                    z++;
                }
                while (j < _size(g) && g[j].fi == g[i].fi) {
                    int id = - g[j].se;
                    mts[store[id].t].erase(mts[store[id].t].find(store[id].x));
                    j++;
                }
                i = j;
            }
            REP(i, q) cout << ans[i] << '\n';
        }
    }
     
    int main() {
        fastio;
     
        cin >> n >> k >> q;
        store.resize(n + 1);
        FOR(i, 1, n) {
            int x, t, a, b;
            cin >> x >> t >> a >> b;
            store[i] = {x, t, a, b};
        }
        qu.resize(q);
        REP(i, q) {
            cin >> qu[i].l >> qu[i].y;
            qu[i].id = i;
        }
        if (max(n, q) <= 60000 && k <= 400) subtask12::main();
        return 0;
    }
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Incorrect 0 ms 348 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Incorrect 0 ms 348 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 117 ms 22116 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 112 ms 21520 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Incorrect 0 ms 348 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Incorrect 0 ms 348 KB Output isn't correct
5 Halted 0 ms 0 KB -