답안 #393590

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
393590 2021-04-24T05:03:26 Z KoD 새 집 (APIO18_new_home) C++17
0 / 100
5000 ms 32296 KB
#include <bits/stdc++.h>

template <class T>
using Vec = std::vector<T>;

using ll = long long;

constexpr ll INF = 1000000000;
constexpr ll MAX = 200000000;

struct Event {
    Vec<int> query;
    Vec<int> remove;
    Event(): query(), remove() { }
};

int main() {
    int N, K, Q;
    std::cin >> N >> K >> Q;
    Vec<ll> X(N), A(N), B(N);
    Vec<int> T(N);
    for (int i = 0; i < N; ++i) {
        std::cin >> X[i] >> T[i] >> A[i] >> B[i];
        assert(A[i] == 1);
        X[i] *= 2;
        T[i] -= 1;
    }
    Vec<ll> L(Q), Y(Q);
    for (int i = 0; i < Q; ++i) {
        std::cin >> L[i] >> Y[i];
        L[i] *= 2;
    }
    Vec<std::multiset<ll>> store(K);
    std::map<ll, ll> map;
    for (int i = 0; i < N; ++i) {
        store[T[i]].insert(X[i]);
    }
    const auto add = [&](const ll x, const ll y) {
        if (map.empty()) {
            map.emplace(x, y);
            return;
        }
        while (map.begin() -> first <= x) {
            auto itr = std::prev(map.upper_bound(x));
            if (itr -> second - (x - itr -> first) >= y) {
                return;
            }
            if (y - (x - itr -> first) >= itr -> second) {
                map.erase(itr);
            }
            else {
                break;
            }
        }
        while (map.rbegin() -> first >= x) {
            auto itr = map.lower_bound(x);
            if (itr -> second - (itr -> first - x) >= y) {
                return;
            }
            if (y - (itr -> first - x) >= itr -> second) {
                map.erase(itr);
            }
            else {
                break;
            }
        }
    };
    const auto get = [&](const ll x) {
        ll min = MAX;
        {
            auto itr = std::prev(map.upper_bound(x));
            min = std::min(min, itr -> second - (x - itr -> first));
        }
        {
            auto itr = map.lower_bound(x);
            min = std::min(min, itr -> second - (itr -> first - x));
        }
        return min;
    };
    for (int i = 0; i < K; ++i) {
        store[i].insert(-INF);
        store[i].insert(INF);
        auto itr = store[i].begin();
        while (std::next(itr) != store[i].end()) {
            const auto mid = (*std::next(itr) + *itr) / 2;
            const auto len = (*std::next(itr) - *itr) / 2;
            add(mid, len);
        }
    }
    for (int i = 0; i < Q; ++i) {
        const auto ans = get(L[i]);
        if (ans == MAX) {
            std::cout << -1 << '\n';
        }
        else {
            std::cout << ans / 2 << '\n';
        }
    }
    // std::map<ll, Event> map;
    // for (int i = 0; i < N; ++i) {

    // }   
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 5021 ms 204 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 5021 ms 204 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 5040 ms 32296 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 5075 ms 29648 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 5021 ms 204 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 5021 ms 204 KB Time limit exceeded
2 Halted 0 ms 0 KB -