Submission #641940

# Submission time Handle Problem Language Result Execution time Memory
641940 2022-09-17T23:39:06 Z maomao90 Road Construction (JOI21_road_construction) C++17
6 / 100
378 ms 5620 KB
// Hallelujah, praise the one who set me free
// Hallelujah, death has lost its grip on me
// You have broken every chain, There's salvation in your name
// Jesus Christ, my living hope
#include <bits/stdc++.h> 
using namespace std;

#define REP(i, s, e) for (int i = (s); i < (e); i++)
#define RREP(i, s, e) for (int i = (s); i >= (e); i--)
template <class T>
inline bool mnto(T& a, T b) {return a > b ? a = b, 1 : 0;}
template <class T>
inline bool mxto(T& a, T b) {return a < b ? a = b, 1: 0;}
typedef long long ll;
typedef long double ld;
#define FI first
#define SE second
typedef pair<int, int> ii;
typedef pair<ll, ll> pll;
typedef tuple<int, int, int> iii;
#define ALL(_a) _a.begin(), _a.end()
#define SZ(_a) (int) _a.size()
#define pb push_back
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ii> vii;
typedef vector<iii> viii;

#ifndef DEBUG
#define cerr if (0) cerr
#endif

const int INF = 1000000005;
const ll LINF = 1000000000000000005ll;
const int MAXN = 250005;

int n, k;
ii xy[MAXN];
vll ans;

bool isPos(ll v) {
    int lft = 0;
    set<ii> st;
    int rk = k;
    REP (i, 0, n) {
        auto [x, y] = xy[i];
        while (lft < i && x - xy[lft].FI > v) {
            st.erase({xy[lft].SE, lft});
            lft++;
        }
        auto ptr = st.lower_bound({y, -1});
        auto optr = ptr;
        while (ptr != st.end() && ptr -> FI - y <= v) {
            if (--rk <= 0) {
                return 1;
            }
            ptr = next(ptr);
        }
        ptr = optr;
        while (ptr != st.begin() && y - prev(ptr) -> FI <= v) {
            if (--rk <= 0) {
                return 1;
            }
            ptr = prev(ptr);
        }
        st.insert({y, i});
    }
    return 0;
}

int main() {
#ifndef DEBUG
    ios::sync_with_stdio(0), cin.tie(0);
#endif
    cin >> n >> k;
    REP (i, 0, n) {
        int x, y; cin >> x >> y;
        xy[i] = {x - y, x + y};
    }
    sort(xy, xy + n);
    ll lo = 0, hi = 4e9 + 5, mid;
    while (lo < hi) {
        mid = lo + hi >> 1;
        if (isPos(mid)) {
            hi = mid;
        } else {
            lo = mid + 1;
        }
    }
    int lft = 0;
    set<ii> st;
    lo--;
    REP (i, 0, n) {
        auto [x, y] = xy[i];
        while (lft < i && (ll) x - xy[lft].FI > lo) {
            auto ptr = st.find({xy[lft].SE, lft});
            assert(ptr != st.end());
            st.erase(ptr);
            lft++;
        }
        auto ptr = st.lower_bound({y, -1});
        auto optr = ptr;
        while (ptr != st.end() && (ll) ptr -> FI - y <= lo) {
            ans.pb(max((ll) x - xy[ptr -> SE].FI, (ll) ptr -> FI - y));
            ptr = next(ptr);
        }
        ptr = optr;
        while (ptr != st.begin() && (ll) y - prev(ptr) -> FI <= lo) {
            ptr = prev(ptr);
            ans.pb(max((ll) x - xy[ptr -> SE].FI, (ll) y - ptr -> FI));
        }
        st.insert({y, i});
    }
    while (SZ(ans) < k) {
        ans.pb(lo + 1);
    }
    sort(ALL(ans));
    for (ll i : ans) {
        cout << i << '\n';
    }
    return 0;
}

Compilation message

road_construction.cpp: In function 'int main()':
road_construction.cpp:84:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   84 |         mid = lo + hi >> 1;
      |               ~~~^~~~
# Verdict Execution time Memory Grader output
1 Correct 119 ms 4948 KB Output is correct
2 Correct 128 ms 4948 KB Output is correct
3 Incorrect 108 ms 5072 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 378 ms 5500 KB Output is correct
2 Correct 358 ms 5616 KB Output is correct
3 Correct 109 ms 4952 KB Output is correct
4 Correct 291 ms 5320 KB Output is correct
5 Correct 280 ms 5620 KB Output is correct
6 Correct 293 ms 5616 KB Output is correct
7 Correct 292 ms 4852 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 110 ms 2212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 110 ms 2212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 119 ms 4948 KB Output is correct
2 Correct 128 ms 4948 KB Output is correct
3 Incorrect 108 ms 5072 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 119 ms 4948 KB Output is correct
2 Correct 128 ms 4948 KB Output is correct
3 Incorrect 108 ms 5072 KB Output isn't correct
4 Halted 0 ms 0 KB -