Submission #641526

# Submission time Handle Problem Language Result Execution time Memory
641526 2022-09-16T23:13:08 Z skittles1412 Road Construction (JOI21_road_construction) C++17
100 / 100
2525 ms 13580 KB
#include "bits/extc++.h"

using namespace std;

template <typename T>
void dbgh(const T& t) {
    cerr << t << endl;
}

template <typename T, typename... U>
void dbgh(const T& t, const U&... u) {
    cerr << t << " | ";
    dbgh(u...);
}

#ifdef DEBUG
#define dbg(...)                                           \
    cerr << "L" << __LINE__ << " [" << #__VA_ARGS__ << "]" \
         << ": ";                                          \
    dbgh(__VA_ARGS__)
#else
#define cerr   \
    if (false) \
    cerr
#define dbg(...)
#endif

#define endl "\n"
#define long int64_t
#define sz(x) int(std::size(x))

namespace __gnu_pbds {
template <typename T, typename U = less<T>>
using ost =
    tree<T, null_type, U, rb_tree_tag, tree_order_statistics_node_update>;
}

using __gnu_pbds::ost;

void solve() {
    int n, kv;
    cin >> n >> kv;
    pair<long, long> arr[n];
    for (auto& [x, y] : arr) {
        long cx, cy;
        cin >> cx >> cy;
        x = cx + cy;
        y = cx - cy;
    }
    sort(arr, arr + n);
    auto check = [&](long cv) -> bool {
        int cans = 0;
        queue<pair<long, int>> q;
        ost<pair<long, int>> s;
        for (int i = 0; i < n; i++) {
            auto& [x, y] = arr[i];
            while (sz(q) && q.front().first < x - cv) {
                int j = q.front().second;
                s.erase({arr[j].second, j});
                q.pop();
            }
            cans += int(s.order_of_key({y + cv + 1, -1}) -
                        s.order_of_key({y - cv, -1}));
            if (cans >= kv) {
                return false;
            }
            s.insert({y, i});
            q.emplace(x, i);
        }
        return true;
    };
    long l = 0, r = 1e10;
    while (l < r) {
        long mid = (l + r + 1) / 2;
        if (check(mid)) {
            l = mid;
        } else {
            r = mid - 1;
        }
    }
    vector<long> ans;
    queue<pair<long, int>> q;
    set<pair<long, int>> s;
    for (int i = 0; i < n; i++) {
        auto& [x, y] = arr[i];
        while (sz(q) && q.front().first < x - l) {
            int j = q.front().second;
            s.erase({arr[j].second, j});
            q.pop();
        }
        for (auto it = s.lower_bound({y - l, -1}),
                  end = s.lower_bound({y + l + 1, -1});
             it != end; ++it) {
            auto& [y1, j] = *it;
            ans.push_back(max(abs(x - arr[j].first), abs(y - y1)));
        }
        s.insert({y, i});
        q.emplace(x, i);
    }
    ans.resize(kv, l + 1);
    sort(begin(ans), end(ans));
    for (auto& a : ans) {
        cout << a << endl;
    }
}

int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cin.exceptions(ios::failbit);
    solve();
}
# Verdict Execution time Memory Grader output
1 Correct 50 ms 5052 KB Output is correct
2 Correct 61 ms 5048 KB Output is correct
3 Correct 45 ms 5032 KB Output is correct
4 Correct 43 ms 5196 KB Output is correct
5 Correct 47 ms 3960 KB Output is correct
6 Correct 4 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 377 ms 10620 KB Output is correct
2 Correct 368 ms 10496 KB Output is correct
3 Correct 51 ms 4904 KB Output is correct
4 Correct 290 ms 10364 KB Output is correct
5 Correct 275 ms 10548 KB Output is correct
6 Correct 304 ms 10616 KB Output is correct
7 Correct 233 ms 9996 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 266 ms 9300 KB Output is correct
2 Correct 348 ms 9296 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 140 ms 7116 KB Output is correct
5 Correct 728 ms 9580 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 266 ms 9300 KB Output is correct
2 Correct 348 ms 9296 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 140 ms 7116 KB Output is correct
5 Correct 728 ms 9580 KB Output is correct
6 Correct 562 ms 9304 KB Output is correct
7 Correct 492 ms 9300 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 407 ms 9412 KB Output is correct
11 Correct 153 ms 7148 KB Output is correct
12 Correct 844 ms 9676 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 50 ms 5052 KB Output is correct
2 Correct 61 ms 5048 KB Output is correct
3 Correct 45 ms 5032 KB Output is correct
4 Correct 43 ms 5196 KB Output is correct
5 Correct 47 ms 3960 KB Output is correct
6 Correct 4 ms 340 KB Output is correct
7 Correct 1083 ms 7996 KB Output is correct
8 Correct 1044 ms 8020 KB Output is correct
9 Correct 45 ms 5164 KB Output is correct
10 Correct 518 ms 7352 KB Output is correct
11 Correct 260 ms 7224 KB Output is correct
12 Correct 522 ms 8052 KB Output is correct
13 Correct 461 ms 6744 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 50 ms 5052 KB Output is correct
2 Correct 61 ms 5048 KB Output is correct
3 Correct 45 ms 5032 KB Output is correct
4 Correct 43 ms 5196 KB Output is correct
5 Correct 47 ms 3960 KB Output is correct
6 Correct 4 ms 340 KB Output is correct
7 Correct 377 ms 10620 KB Output is correct
8 Correct 368 ms 10496 KB Output is correct
9 Correct 51 ms 4904 KB Output is correct
10 Correct 290 ms 10364 KB Output is correct
11 Correct 275 ms 10548 KB Output is correct
12 Correct 304 ms 10616 KB Output is correct
13 Correct 233 ms 9996 KB Output is correct
14 Correct 266 ms 9300 KB Output is correct
15 Correct 348 ms 9296 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 140 ms 7116 KB Output is correct
18 Correct 728 ms 9580 KB Output is correct
19 Correct 562 ms 9304 KB Output is correct
20 Correct 492 ms 9300 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 407 ms 9412 KB Output is correct
24 Correct 153 ms 7148 KB Output is correct
25 Correct 844 ms 9676 KB Output is correct
26 Correct 1083 ms 7996 KB Output is correct
27 Correct 1044 ms 8020 KB Output is correct
28 Correct 45 ms 5164 KB Output is correct
29 Correct 518 ms 7352 KB Output is correct
30 Correct 260 ms 7224 KB Output is correct
31 Correct 522 ms 8052 KB Output is correct
32 Correct 461 ms 6744 KB Output is correct
33 Correct 2486 ms 13432 KB Output is correct
34 Correct 2525 ms 13428 KB Output is correct
35 Correct 1511 ms 12668 KB Output is correct
36 Correct 1055 ms 13580 KB Output is correct
37 Correct 998 ms 13548 KB Output is correct
38 Correct 1130 ms 12288 KB Output is correct