Submission #1200319

#TimeUsernameProblemLanguageResultExecution timeMemory
1200319boycl08Road Construction (JOI21_road_construction)C++20
6 / 100
1446 ms23004 KiB
#include <bits/stdc++.h>
#include <cmath>
using namespace std;

typedef long long ll;

#define int ll
#define rep(i, n) for(int i = 1; (i) <= (n); ++i)
#define forn(i, l, r) for(int i = (l); i <= (r); ++i)
#define ford(i, r, l) for(int i = (r); i >= (l); --i)
#define FOR(i, n) for(int i = 0; i < (n); ++i)
#define FORD(i, n) for(int i = ((n) - 1); i >= 0; --i)
#define fi first
#define se second
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define task "note"
#define endl "\n"
#define sz(a) int(a.size())
#define C(x, y) make_pair(x, y)
#define all(a) (a).begin(), (a).end()
#define bit(i, mask) (mask >> i & 1)

template<typename T> bool maximize(T &res, const T &val) { if (res < val){ res = val; return true; }; return false; }
template<typename T> bool minimize(T &res, const T &val) { if (res > val){ res = val; return true; }; return false; }
const int N = 5e5 + 33;
const ll INF = 1e18;
const int LINF = 1e9;
const int LIM = 1e6 + 1;
const int MOD = 1e9 + 7;
const int base = 1e5 + 7;
int n, k;
pii X[N];
vector<int> ans;
int dist(int x, int y)
{
    return max(abs(X[x].fi - X[y].fi), abs(X[x].se - X[y].se));
}
bool check(int max_dist)
{
    set<pii> s;
    ans.clear();
    for(int i = 1, j = 1; i <= n; ++i)
    {
        while(X[i].fi - X[j].fi > max_dist)
            s.erase({X[j].se, j}), ++j;
        auto it = s.lower_bound({X[j].se - max_dist, -1});
        while(sz(ans) < k && it != s.end() && it -> fi <= max_dist + X[i].se)
        {
            ans.pb(dist(i, it -> se));
            ++it;
        }
        s.insert({X[i].se, i});
    }
    return sz(ans) < k;
}

void solve()
{
    cin >> n >> k;
    rep(i, n)
    {
        int u, v;
        cin >> u >> v;
        X[i] = {u + v, u - v};
    }
    sort(X + 1, X + 1 + n);
    int l = 0, r = 4e9, k_th = 0;
    while(l <= r)
    {   
        int mid = l + r >> 1;
        if(check(mid)) k_th = mid, l = mid + 1;
        else r = mid - 1;
    }
    
    check(k_th);
    while(sz(ans) < k) ans.pb(k_th + 1);
    sort(all(ans));
    for(int x : ans) cout << x  << "\n";
    
}

signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int TC = 1;
    if(fopen(task".inp", "r"))
    {
        freopen(task".inp", "r", stdin);
        freopen(task".out", "w", stdout);
    }
    
    while(TC--)
    {
        solve();
        cout << endl;
    }

    return 0;
}

Compilation message (stderr)

road_construction.cpp: In function 'int main()':
road_construction.cpp:91:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   91 |         freopen(task".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
road_construction.cpp:92:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   92 |         freopen(task".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...