Submission #872703

# Submission time Handle Problem Language Result Execution time Memory
872703 2023-11-13T15:19:28 Z serifefedartar Road Construction (JOI21_road_construction) C++17
6 / 100
4059 ms 26084 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 max(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] << "\n";
}
# Verdict Execution time Memory Grader output
1 Correct 53 ms 5052 KB Output is correct
2 Correct 54 ms 5052 KB Output is correct
3 Incorrect 47 ms 5056 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2869 ms 22184 KB Output is correct
2 Correct 2854 ms 22208 KB Output is correct
3 Correct 41 ms 5056 KB Output is correct
4 Correct 2866 ms 24812 KB Output is correct
5 Correct 4059 ms 25024 KB Output is correct
6 Correct 4048 ms 25180 KB Output is correct
7 Correct 3344 ms 24420 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3529 ms 20924 KB Output is correct
2 Correct 3557 ms 26084 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3529 ms 20924 KB Output is correct
2 Correct 3557 ms 26084 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 53 ms 5052 KB Output is correct
2 Correct 54 ms 5052 KB Output is correct
3 Incorrect 47 ms 5056 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 53 ms 5052 KB Output is correct
2 Correct 54 ms 5052 KB Output is correct
3 Incorrect 47 ms 5056 KB Output isn't correct
4 Halted 0 ms 0 KB -