Submission #921618

# Submission time Handle Problem Language Result Execution time Memory
921618 2024-02-04T08:14:54 Z guagua0407 Road Construction (JOI21_road_construction) C++17
7 / 100
9876 ms 55828 KB
//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define int ll
#define pii pair<int,int>
#define f first
#define s second
#define all(x) x.begin(),x.end()
#define _ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

int dx[4]={0,0,1,-1};
int dy[4]={1,-1,0,0};

void setIO(string s) {
    freopen((s + ".in").c_str(), "r", stdin);
    freopen((s + ".out").c_str(), "w", stdout);
}

const int mxn=250005;
int n,k;
vector<pair<int,int>> vec;
vector<int> xs,ys;
vector<vector<int>> sir;
int bit[mxn];

void update(int pos,int val){
    pos++;
    for(;pos<mxn;pos+=(pos&-pos)){
        bit[pos]+=val;
    }
}

int query(int pos){
    pos++;
    int ans=0;
    for(;pos>0;pos-=(pos&-pos)){
        ans+=bit[pos];
    }
    return ans;
}

bool ok(int d){
    vector<vector<pair<int,int>>> st(xs.size()),en(xs.size());
    for(int i=0;i<n;i++){
        int l=lower_bound(all(xs),xs[vec[i].f]-d)-xs.begin();
        int r=upper_bound(all(xs),xs[vec[i].f]+d)-xs.begin()-1;
        int l2=lower_bound(all(ys),ys[vec[i].s]-d)-ys.begin();
        int r2=upper_bound(all(ys),ys[vec[i].s]+d)-ys.begin()-1;
        if(l>0){
            st[l-1].push_back({l2,r2});
        }
        en[vec[i].f].push_back({l2,r2});
    }

    int ans=0;
    for(int i=0;i<(int)xs.size();i++){
        for(auto v:sir[i]){
            update(v,1);
        }
        for(auto v:st[i]){
            ans-=(query(v.s)-query(v.f-1));
        }
        for(auto v:en[i]){
            ans+=(query(v.s)-query(v.f-1));
        }
    }
    ans-=n;
    //cout<<d<<' '<<ans<<'\n';
    for(int i=0;i<n;i++){
        update(vec[i].s,-1);
    }
    return ans>=k;
}

signed main() {_
    cin>>n>>k;
    vec.resize(n);
    for(int i=0;i<n;i++){
        int x,y;
        cin>>x>>y;
        int xx=y+x;
        int yy=y-x;
        vec[i]={xx,yy};
        xs.push_back(xx);
        ys.push_back(yy);
    }
    sort(all(xs));
    sort(all(ys));
    xs.resize(unique(all(xs))-xs.begin());
    ys.resize(unique(all(ys))-ys.begin());
    sir.resize(xs.size());
    for(int i=0;i<n;i++){
        //cout<<vec[i].f<<' '<<vec[i].s<<'\n';
        vec[i].f=lower_bound(all(xs),vec[i].f)-xs.begin();
        vec[i].s=lower_bound(all(ys),vec[i].s)-ys.begin();
        sir[vec[i].f].push_back(vec[i].s);
    }
    ll l=0,r=(ll)4e9;
    while(l<r){
        ll mid=(l+r)/2;
        if(ok(mid)){
            r=mid;
        }
        else{
            l=mid+1;
        }
    }
    cout<<l<<'\n';
    return 0;
}
//maybe its multiset not set
//yeeorz
//laborz

Compilation message

road_construction.cpp: In function 'bool ok(long long int)':
road_construction.cpp:47:13: warning: unused variable 'r' [-Wunused-variable]
   47 |         int r=upper_bound(all(xs),xs[vec[i].f]+d)-xs.begin()-1;
      |             ^
road_construction.cpp: In function 'void setIO(std::string)':
road_construction.cpp:16:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   16 |     freopen((s + ".in").c_str(), "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
road_construction.cpp:17:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   17 |     freopen((s + ".out").c_str(), "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 9 ms 512 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 9606 ms 53084 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 9570 ms 55828 KB Output is correct
2 Correct 9876 ms 55344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 9565 ms 54252 KB Output is correct
5 Correct 2131 ms 28296 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9570 ms 55828 KB Output is correct
2 Correct 9876 ms 55344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 9565 ms 54252 KB Output is correct
5 Correct 2131 ms 28296 KB Output is correct
6 Incorrect 9566 ms 55136 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 9 ms 512 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 9 ms 512 KB Output isn't correct
2 Halted 0 ms 0 KB -