Submission #1111322

# Submission time Handle Problem Language Result Execution time Memory
1111322 2024-11-12T05:11:24 Z onlk97 Road Construction (JOI21_road_construction) C++14
100 / 100
3973 ms 28964 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define int long long
#define x first
#define y second
#define pb push_back
using namespace std;
using namespace __gnu_pbds;
using pii=pair <int,int>;
signed main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n,k;
    cin>>n>>k;
    pii a[n+1];
    for (int i=1; i<=n; i++){
        int u,v; cin>>u>>v;
        a[i]={u-v,u+v};
    }
    sort(a+1,a+n+1);
    int l=1,r=4e9;
    tree <pii,null_type,less <pii>,rb_tree_tag,tree_order_statistics_node_update> s;
    while (l<r){
        int mid=(l+r)/2;
        s.clear();
        int cnt=0,lst=1;
        for (int i=1; i<=n; i++){
            while (lst<i&&a[lst].x<a[i].x-mid){
                s.erase({a[lst].y,lst});
                lst++;
            }
            cnt+=s.order_of_key({a[i].y+mid+1,0})-s.order_of_key({a[i].y-mid,0});
            s.insert({a[i].y,i});
        }
        if (cnt>=k) r=mid;
        else l=mid+1;
    }
    l--;
    vector <int> vec;
    s.clear();
    int lst=1;
    for (int i=1; i<=n; i++){
        while (lst<i&&a[lst].x<a[i].x-l){
            s.erase({a[lst].y,lst});
            lst++;
        }
        int idx=s.order_of_key({a[i].y-l,0});
        while (idx<s.size()){
            pii tp=*s.find_by_order(idx);
            if (tp.x>a[i].y+l) break;
            vec.pb(max(a[i].x-a[tp.y].x,abs(a[i].y-tp.x)));
            idx++;
        }
        s.insert({a[i].y,i});
    }
    sort(vec.begin(),vec.end());
    while (vec.size()<k) vec.pb(l+1);
    for (int i:vec) cout<<i<<'\n';
}

Compilation message

road_construction.cpp: In function 'int main()':
road_construction.cpp:48:19: warning: comparison of integer expressions of different signedness: 'long long int' and '__gnu_pbds::detail::bin_search_tree_set<std::pair<long long int, long long int>, __gnu_pbds::null_type, std::less<std::pair<long long int, long long int> >, __gnu_pbds::detail::tree_traits<std::pair<long long int, long long int>, __gnu_pbds::null_type, std::less<std::pair<long long int, long long int> >, __gnu_pbds::tree_order_statistics_node_update, __gnu_pbds::rb_tree_tag, std::allocator<char> >, std::allocator<char> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   48 |         while (idx<s.size()){
      |                ~~~^~~~~~~~~
road_construction.cpp:57:22: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   57 |     while (vec.size()<k) vec.pb(l+1);
      |            ~~~~~~~~~~^~
# Verdict Execution time Memory Grader output
1 Correct 47 ms 5256 KB Output is correct
2 Correct 45 ms 5076 KB Output is correct
3 Correct 39 ms 5324 KB Output is correct
4 Correct 39 ms 5308 KB Output is correct
5 Correct 40 ms 4060 KB Output is correct
6 Correct 4 ms 592 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1184 ms 24064 KB Output is correct
2 Correct 1238 ms 24060 KB Output is correct
3 Correct 37 ms 5076 KB Output is correct
4 Correct 1128 ms 24060 KB Output is correct
5 Correct 1095 ms 23964 KB Output is correct
6 Correct 1105 ms 24136 KB Output is correct
7 Correct 1187 ms 23672 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2349 ms 21064 KB Output is correct
2 Correct 2457 ms 21172 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1101 ms 23164 KB Output is correct
5 Correct 2661 ms 25160 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2349 ms 21064 KB Output is correct
2 Correct 2457 ms 21172 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1101 ms 23164 KB Output is correct
5 Correct 2661 ms 25160 KB Output is correct
6 Correct 2528 ms 21176 KB Output is correct
7 Correct 2315 ms 21144 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 2351 ms 21160 KB Output is correct
11 Correct 1069 ms 22944 KB Output is correct
12 Correct 2333 ms 25332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 47 ms 5256 KB Output is correct
2 Correct 45 ms 5076 KB Output is correct
3 Correct 39 ms 5324 KB Output is correct
4 Correct 39 ms 5308 KB Output is correct
5 Correct 40 ms 4060 KB Output is correct
6 Correct 4 ms 592 KB Output is correct
7 Correct 1278 ms 12760 KB Output is correct
8 Correct 1309 ms 12572 KB Output is correct
9 Correct 42 ms 5312 KB Output is correct
10 Correct 909 ms 11908 KB Output is correct
11 Correct 744 ms 11888 KB Output is correct
12 Correct 693 ms 14112 KB Output is correct
13 Correct 953 ms 10796 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 47 ms 5256 KB Output is correct
2 Correct 45 ms 5076 KB Output is correct
3 Correct 39 ms 5324 KB Output is correct
4 Correct 39 ms 5308 KB Output is correct
5 Correct 40 ms 4060 KB Output is correct
6 Correct 4 ms 592 KB Output is correct
7 Correct 1184 ms 24064 KB Output is correct
8 Correct 1238 ms 24060 KB Output is correct
9 Correct 37 ms 5076 KB Output is correct
10 Correct 1128 ms 24060 KB Output is correct
11 Correct 1095 ms 23964 KB Output is correct
12 Correct 1105 ms 24136 KB Output is correct
13 Correct 1187 ms 23672 KB Output is correct
14 Correct 2349 ms 21064 KB Output is correct
15 Correct 2457 ms 21172 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 1101 ms 23164 KB Output is correct
18 Correct 2661 ms 25160 KB Output is correct
19 Correct 2528 ms 21176 KB Output is correct
20 Correct 2315 ms 21144 KB Output is correct
21 Correct 1 ms 336 KB Output is correct
22 Correct 1 ms 336 KB Output is correct
23 Correct 2351 ms 21160 KB Output is correct
24 Correct 1069 ms 22944 KB Output is correct
25 Correct 2333 ms 25332 KB Output is correct
26 Correct 1278 ms 12760 KB Output is correct
27 Correct 1309 ms 12572 KB Output is correct
28 Correct 42 ms 5312 KB Output is correct
29 Correct 909 ms 11908 KB Output is correct
30 Correct 744 ms 11888 KB Output is correct
31 Correct 693 ms 14112 KB Output is correct
32 Correct 953 ms 10796 KB Output is correct
33 Correct 3914 ms 22968 KB Output is correct
34 Correct 3973 ms 22984 KB Output is correct
35 Correct 2737 ms 22204 KB Output is correct
36 Correct 2553 ms 28964 KB Output is correct
37 Correct 2470 ms 28908 KB Output is correct
38 Correct 2765 ms 25844 KB Output is correct