답안 #1010680

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1010680 2024-06-29T09:31:01 Z Unforgettablepl Road Construction (JOI21_road_construction) C++17
100 / 100
8023 ms 417844 KB
#pragma GCC optimize("Ofast","unroll-loops")
#include <bits/stdc++.h>
using namespace std;
 
 
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
 
#define int long long
typedef tree<pair<int,int>,null_type,less<>,rb_tree_tag,tree_order_statistics_node_update> orderedset;
 
orderedset seg[1000000];
vector<pair<int,int>> points;
vector<pair<int,int>> edges;
int n;

void build(int x=1,int L=1,int R=n){
    if(L==R){
        seg[x].insert({points[L].second,L});
        return;
    }
    int mid = (L+R)/2;
    build(2*x,L,mid);
    build(2*x+1,mid+1,R);
    for(auto i:seg[2*x])seg[x].insert(i);
    for(auto i:seg[2*x+1])seg[x].insert(i);
}
 
int get(int qL,int qR,int qUpper,int qLower,int x=1,int L=1,int R=n){
    if(qR<L or R<qL)return 0;
    if(qL<=L and R<=qR){
        return seg[x].order_of_key({qUpper+1,0})-seg[x].order_of_key({qLower,0});
    }
    int mid = (L+R)/2;
    return get(qL,qR,qUpper,qLower,2*x,L,mid)+get(qL,qR,qUpper,qLower,2*x+1,mid+1,R);
}
 
int base;
 
void rec(int qL,int qR,int qUpper,int qLower,int x=1,int L=1,int R=n){
    if(qR<L or R<qL)return;
    if(qL<=L and R<=qR){
        auto lo = seg[x].order_of_key({qLower,0});
        auto hi = seg[x].order_of_key({qUpper+1,0});
        while(lo!=hi){
            edges.emplace_back(min(base,(int)seg[x].find_by_order(lo)->second),max(base,(int)seg[x].find_by_order(lo)->second));
            lo++;
        }
        return;
    }
    int mid = (L+R)/2;
    rec(qL,qR,qUpper,qLower,2*x,L,mid);
    rec(qL,qR,qUpper,qLower,2*x+1,mid+1,R);
}
 
 
int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int k;
    cin >> n >> k;
    for(int i=1;i<=n;i++){
        int x,y;
        cin >> x >> y;
        points.emplace_back(x-y,x+y);
    }
    sort(points.begin(),points.end());
    points.insert(points.begin(),{0,0});
    build();
    auto calc = [&](int limit){
        int curr = -n;
        for(int i=1;i<=n;i++){
            int qL = lower_bound(points.begin()+1,points.end(),make_pair(points[i].first-limit,(int)-1e15))-points.begin();
            int qR = lower_bound(points.begin()+1,points.end(),make_pair(points[i].first+limit,(int)-1e15))-points.begin()-1;
            curr+=get(qL,qR,points[i].second+limit,points[i].second-limit);
            if(curr>=2*k)return false;
        }
        return curr<2*k;
    };
    vector<int> edgewt;
    auto recover = [&](int limit){
        for(int i=1;i<=n;i++){
            int qL = lower_bound(points.begin(),points.end(),make_pair(points[i].first-limit,(int)-1e15))-points.begin();
            int qR = lower_bound(points.begin(),points.end(),make_pair(points[i].first+limit,(int)-1e15))-points.begin()-1;
            base = i;
            rec(qL,qR,points[i].second+limit,points[i].second-limit);
        }
        sort(edges.begin(),edges.end());
        edges.erase(unique(edges.begin(),edges.end()),edges.end());
        for(auto[a,b]:edges){
            if(a==b)continue;
            edgewt.emplace_back(max(abs(points[a].first-points[b].first),abs(points[a].second-points[b].second)));
        }
        sort(edgewt.begin(),edgewt.end());
    };
    int ans = 0;
    #pragma GCC unroll 40
    for(int jump=2147483648ll;jump;jump/=2)if(calc(ans+jump))ans+=jump;
    recover(ans);
    for(int i=0;i<k;i++){
        if(i<edgewt.size())cout<<edgewt[i]<<'\n';
        else cout<<ans+1<<'\n';
    }
}

Compilation message

road_construction.cpp: In function 'int32_t main()':
road_construction.cpp:101:13: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  101 |         if(i<edgewt.size())cout<<edgewt[i]<<'\n';
      |            ~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 205 ms 109520 KB Output is correct
2 Correct 191 ms 109424 KB Output is correct
3 Correct 174 ms 109328 KB Output is correct
4 Correct 150 ms 109232 KB Output is correct
5 Correct 145 ms 108208 KB Output is correct
6 Correct 70 ms 95056 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2395 ms 411932 KB Output is correct
2 Correct 2416 ms 414772 KB Output is correct
3 Correct 191 ms 109228 KB Output is correct
4 Correct 2164 ms 414764 KB Output is correct
5 Correct 1985 ms 414740 KB Output is correct
6 Correct 2178 ms 415016 KB Output is correct
7 Correct 2188 ms 414572 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3320 ms 403768 KB Output is correct
2 Correct 3303 ms 406200 KB Output is correct
3 Correct 56 ms 94308 KB Output is correct
4 Correct 2012 ms 404056 KB Output is correct
5 Correct 2727 ms 406480 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3320 ms 403768 KB Output is correct
2 Correct 3303 ms 406200 KB Output is correct
3 Correct 56 ms 94308 KB Output is correct
4 Correct 2012 ms 404056 KB Output is correct
5 Correct 2727 ms 406480 KB Output is correct
6 Correct 3646 ms 406228 KB Output is correct
7 Correct 3486 ms 405988 KB Output is correct
8 Correct 51 ms 94364 KB Output is correct
9 Correct 69 ms 94368 KB Output is correct
10 Correct 3349 ms 406236 KB Output is correct
11 Correct 1812 ms 404076 KB Output is correct
12 Correct 2585 ms 406356 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 205 ms 109520 KB Output is correct
2 Correct 191 ms 109424 KB Output is correct
3 Correct 174 ms 109328 KB Output is correct
4 Correct 150 ms 109232 KB Output is correct
5 Correct 145 ms 108208 KB Output is correct
6 Correct 70 ms 95056 KB Output is correct
7 Correct 3229 ms 225172 KB Output is correct
8 Correct 3237 ms 225256 KB Output is correct
9 Correct 176 ms 109228 KB Output is correct
10 Correct 1861 ms 225272 KB Output is correct
11 Correct 1061 ms 225244 KB Output is correct
12 Correct 1624 ms 227256 KB Output is correct
13 Correct 1136 ms 225400 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 205 ms 109520 KB Output is correct
2 Correct 191 ms 109424 KB Output is correct
3 Correct 174 ms 109328 KB Output is correct
4 Correct 150 ms 109232 KB Output is correct
5 Correct 145 ms 108208 KB Output is correct
6 Correct 70 ms 95056 KB Output is correct
7 Correct 2395 ms 411932 KB Output is correct
8 Correct 2416 ms 414772 KB Output is correct
9 Correct 191 ms 109228 KB Output is correct
10 Correct 2164 ms 414764 KB Output is correct
11 Correct 1985 ms 414740 KB Output is correct
12 Correct 2178 ms 415016 KB Output is correct
13 Correct 2188 ms 414572 KB Output is correct
14 Correct 3320 ms 403768 KB Output is correct
15 Correct 3303 ms 406200 KB Output is correct
16 Correct 56 ms 94308 KB Output is correct
17 Correct 2012 ms 404056 KB Output is correct
18 Correct 2727 ms 406480 KB Output is correct
19 Correct 3646 ms 406228 KB Output is correct
20 Correct 3486 ms 405988 KB Output is correct
21 Correct 51 ms 94364 KB Output is correct
22 Correct 69 ms 94368 KB Output is correct
23 Correct 3349 ms 406236 KB Output is correct
24 Correct 1812 ms 404076 KB Output is correct
25 Correct 2585 ms 406356 KB Output is correct
26 Correct 3229 ms 225172 KB Output is correct
27 Correct 3237 ms 225256 KB Output is correct
28 Correct 176 ms 109228 KB Output is correct
29 Correct 1861 ms 225272 KB Output is correct
30 Correct 1061 ms 225244 KB Output is correct
31 Correct 1624 ms 227256 KB Output is correct
32 Correct 1136 ms 225400 KB Output is correct
33 Correct 8023 ms 417844 KB Output is correct
34 Correct 7552 ms 417652 KB Output is correct
35 Correct 4104 ms 417044 KB Output is correct
36 Correct 2840 ms 406376 KB Output is correct
37 Correct 2818 ms 406224 KB Output is correct
38 Correct 3192 ms 416828 KB Output is correct