Submission #797054

# Submission time Handle Problem Language Result Execution time Memory
797054 2023-07-29T05:26:53 Z vjudge1 Road Construction (JOI21_road_construction) C++17
7 / 100
2621 ms 15680 KB
#include <bits/stdc++.h>

#define fi first
#define se second

const int N = 300300;

using namespace std;

int n;
int id[N];
int t[N];
pair < long long, long long > a[N];
vector < pair < long long, int > > v;

void upd(int x, int g)
{
        while(x < N){
                t[x] += g;
                x += x & -x;
        }
}

int get_c(int x)
{
        int res = 0;
        while(x > 0){
                res += t[x];
                x -= x & -x;
        }
        return res;
}

long long get(long long D)
{
        long long res = 0;
        for(int i = 0; i < N; i++) t[i] = 0;

        for(int i = 1, j = 1; i <= n; i++){
                if(i > 1){
                        upd(id[i - 1], 1);
                }
                while(j < i && a[i].fi - a[j].fi > D){
                        upd(id[j], -1);
                        j += 1;
                }
                int l = lower_bound(v.begin(), v.end(), make_pair(a[i].se - D, 0)) - v.begin();
                int r = lower_bound(v.begin(), v.end(), make_pair(a[i].se + D + 1, 0)) - v.begin() - 1;
                if(l <= r){
                        res += get_c(v[r].se) - get_c(v[l].se - 1);
                }
        }
        return res;
}

int main()
{
        ios_base::sync_with_stdio(0);

        //freopen("input.txt", "r", stdin);
        //freopen("output.txt", "w", stdout);

        long long k;
        cin >> n >> k;
        for(int i = 1; i <= n; i++){
                int x, y;
                cin >> x >> y;

                a[i] = {x + y, x - y};
        }
        sort(a + 1, a + n + 1);

        v.push_back({-4e9 - 1, 0});
        v.push_back({4e9 + 1, 0});

        for(int i = 1; i <= n; i++){
                v.push_back({a[i].se, i});
        }
        sort(v.begin(), v.end());
        for(int i = 0, j = 0; i < v.size(); i++){
                if(i > 0 && v[i].fi > v[i - 1].fi){
                        j += 1;
                }
                id[v[i].se] = j;
                v[i].se = j;
        }

        long long l = 0, r = 4e9;
        while(l < r){
                long long m = (l + r) / 2;
                if(get(m) >= k){
                        r = m;
                } else{
                        l = m + 1;
                }
        }

        cout << l << "\n";
}

Compilation message

road_construction.cpp: In function 'int main()':
road_construction.cpp:80:33: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   80 |         for(int i = 0, j = 0; i < v.size(); i++){
      |                               ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 1492 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1222 ms 10408 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2608 ms 10432 KB Output is correct
2 Correct 2615 ms 10352 KB Output is correct
3 Correct 2 ms 1492 KB Output is correct
4 Correct 1225 ms 13320 KB Output is correct
5 Correct 2157 ms 15680 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2608 ms 10432 KB Output is correct
2 Correct 2615 ms 10352 KB Output is correct
3 Correct 2 ms 1492 KB Output is correct
4 Correct 1225 ms 13320 KB Output is correct
5 Correct 2157 ms 15680 KB Output is correct
6 Incorrect 2621 ms 15508 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 1492 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 1492 KB Output isn't correct
2 Halted 0 ms 0 KB -