Submission #872697

# Submission time Handle Problem Language Result Execution time Memory
872697 2023-11-13T15:11:08 Z serifefedartar Road Construction (JOI21_road_construction) C++17
0 / 100
3542 ms 25060 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
 
#define fast ios::sync_with_stdio(0);cin.tie(0);
#define s second
#define f first
typedef long long ll;
const ll MOD = 1e9+9;
const ll LOGN = 20; 
const ll MAXN = 2e5 + 100;

vector<pair<int,int>> pnt;
vector<pair<int, pair<int,int>>> v;
vector<ll> ans;
ll N, K;
int manh(int i, int j) {
	return abs(pnt[i].f - pnt[j].f) + abs(pnt[i].s - pnt[j].s);
}

bool check(ll mid, int type) {
	ll q = (ll)v.size(), r = 0;
	ll cnt = 0;

	tree<pair<ll,ll>, null_type, less<pair<ll,ll>>, rb_tree_tag, tree_order_statistics_node_update> oset;
	for (int l = 0; l < q; l++) {
		while (r + 1 < q && v[r+1].f - v[l].f <= mid) {
			r++;
			for (int i = v[r].s.f; i <= v[r].s.s; i++)
				oset.insert({pnt[i].s, i});
		}

		for (int i = v[l].s.f; i <= v[l].s.s; i++)
			oset.erase({pnt[i].s, i});

		for (int i = v[l].s.f; i <= v[l].s.s; i++) {
			oset.insert({pnt[i].s, i});
			int lPtr = oset.order_of_key(make_pair(pnt[i].s - mid, -1));
			int rPtr = oset.order_of_key(make_pair(pnt[i].s + mid, 1e8)) - 1;
			cnt += rPtr - lPtr;
			if (type) {
				for (int j = lPtr; j <= rPtr; j++) {
					int no = (*oset.find_by_order(j)).s;
					if (no != i)
						ans.push_back(manh(i, no));
				}				
			}
		}

		for (int i = v[l].s.f; i <= v[l].s.s; i++)
			oset.erase({pnt[i].s, i});
	}

	return (cnt >= K);
}

int main() {
	fast
	cin >> N >> K;

	pnt = vector<pair<int,int>>(N);
	for (int i = 0; i < N; i++) {
		cin >> pnt[i].f >> pnt[i].s;
		int x = pnt[i].f + pnt[i].s;
		int y = pnt[i].f - pnt[i].s;
		pnt[i] = {x, y};
	}
	sort(pnt.begin(), pnt.end());

	for (int i = 0; i < N; i++) {
		int j = i;
		while (j < N && pnt[i].f == pnt[j].f)
			j++;
		v.push_back({pnt[i].f, {i, j-1}});
		i = j-1;
	}

	ll L = 1;
	ll R = 1e10;
	ll res = -1;
	while (R >= L) {
		ll mid = L + (R-L)/2;
		if (check(mid, 0)) {
			R = mid - 1;
			res = mid;
		} else
			L = mid + 1;
	}
	check(res, 1);

	sort(ans.begin(), ans.end());
	for (int i = 0; i < K; i++)
		cout << ans[i] / 2 << "\n";
}
# Verdict Execution time Memory Grader output
1 Incorrect 54 ms 5056 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2836 ms 22028 KB Output is correct
2 Correct 2847 ms 25060 KB Output is correct
3 Incorrect 41 ms 4924 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3542 ms 20928 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3542 ms 20928 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 54 ms 5056 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 54 ms 5056 KB Output isn't correct
2 Halted 0 ms 0 KB -