답안 #393033

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
393033 2021-04-22T15:10:38 Z nvmdava Road Construction (JOI21_road_construction) C++17
6 / 100
626 ms 23264 KB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ff first
#define ss second
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int N = 1000005;
const ll MOD = 1000000007;
const ll INF = 0x3f3f3f3f3f3f3f3f;
 
vector<pair<ll, int> > s, d;
 
ll a[N], b[N];
int loc[N], w[N], rev[N];
int n;
ll k;

int fen[N];

void update(int x, int v){
    while(x <= n){
        fen[x] += v;
        x += x & -x;
    }
}

int query(int x){
    int res = 0;
    while(x){
        res += fen[x];
        x -= x & -x;
    }
    return res;
}
 
vector<ll> ans;
int l1[N], r1[N];
bool count(ll len){
    ll cnt = 0;
    l1[0] = 1;
    r1[0] = 1;
    for(int i = 1; i <= n; ++i){
        l1[i] = l1[i - 1];
        while(a[l1[i]] < a[i] - len)
            ++l1[i];
        r1[i] = r1[i - 1];
        while(r1[i] < n && a[r1[i] + 1] <= a[i] + len)
            ++r1[i];
    }

    int l = 1;
    for(int i = 1; i <= n; ++i){
        while(b[l] < b[i] - len)
            update(w[l++], -1);
        cnt += query(r1[i]) - query(l1[i] - 1);
        if(cnt >= k){
            for(; l < i; ++l)
                update(w[l], -1);
            return 0;
        }

        update(w[i], 1);
    }
    for(; l <= n; ++l)
        update(w[l], -1);
    return 1;
}

void find(ll len){
    set<pair<ll, int> > in;
    int l = 1;
    for(int i = 1; i <= n; ++i){
        while(a[l] < a[i] - len){
            in.erase({b[rev[l]], l});
            ++l;
        }
        auto it = in.lower_bound({b[rev[i]] - len, 0});
        while(it != in.end() && it -> ff <= b[rev[i]] + len){
            ans.push_back(max(abs(b[rev[i]] - it -> ff), abs(a[i] - a[it -> ss])));
            ++it;
        }
        in.insert({b[rev[i]], i});
    }
}
 
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
 
    cin>>n>>k;
 
    for(int x, y, i = 1; i <= n; ++i){
        cin>>x>>y;
        s.push_back({x + y, i});
        d.push_back({x - y, i});
    }
    sort(s.begin(), s.end());
    sort(d.begin(), d.end());
 
    for(int i = 1; i <= n; ++i){
        a[i] = s[i - 1].ff;
        loc[s[i - 1].ss] = i;
    }
    for(int i = 1; i <= n; ++i){
        b[i] = d[i - 1].ff;
        w[i] = loc[d[i - 1].ss];
        rev[w[i]] = i;
    }
    
    ll len = 0;
    for(int i = 31; i >= 0; --i)
        if(count((1LL << i) | len))
            len |= 1LL << i;
    find(len);
    sort(ans.begin(), ans.end());
    ++len;
    while(ans.size() < k)
        ans.push_back(len);
    for(auto& x : ans)
        cout<<x<<'\n';
}

Compilation message

road_construction.cpp: In function 'int main()':
road_construction.cpp:118: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]
  118 |     while(ans.size() < k)
      |           ~~~~~~~~~~~^~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 56 ms 5044 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 614 ms 23168 KB Output is correct
2 Correct 623 ms 23264 KB Output is correct
3 Correct 49 ms 5036 KB Output is correct
4 Correct 480 ms 22944 KB Output is correct
5 Correct 342 ms 23180 KB Output is correct
6 Correct 356 ms 23192 KB Output is correct
7 Correct 397 ms 22728 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 626 ms 18108 KB Output is correct
2 Incorrect 592 ms 18112 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 626 ms 18108 KB Output is correct
2 Incorrect 592 ms 18112 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 56 ms 5044 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 56 ms 5044 KB Output isn't correct
2 Halted 0 ms 0 KB -