답안 #392954

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
392954 2021-04-22T12:14:52 Z Mlxa Road Construction (JOI21_road_construction) C++14
6 / 100
5485 ms 52060 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;

using ll = long long;
#define int ll
#define x first
#define y second
#define mp make_pair
#define mt make_tuple
#define all(x) x.begin(), x.end()

const int N = 1 << 18, INF = 1e18;
const int OPEN = -1, QUERY = 0, CLOSE = 1;

template<class T>
using iset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

int n, k;
pair<int, int> p[N];
iset<pair<int, int>> q;

int query(int c) {
	vector<tuple<int, int, int>> scan;
	for (int i = 0; i < n; ++i) {
		scan.emplace_back(p[i].x - c,  OPEN, p[i].y);
		scan.emplace_back(p[i].x,     QUERY, p[i].y);
		scan.emplace_back(p[i].x + c, CLOSE, p[i].y);
	}
	sort(all(scan));
	q.clear();
	int answer = 0;
	for (auto e : scan) {
		int x, t, y;
		tie(x, t, y) = e;
		if (t == OPEN) {
			q.insert(mp(y, x + c));
		} else if (t == CLOSE) {
			q.erase(mp(y, x - c));
		} else {
			int lef = q.order_of_key(mp(y - c, -INF)),
				rig = q.order_of_key(mp(y + c, +INF));
			answer += rig - lef - 1;
		}
	}
	assert(answer % 2 == 0);
	return answer /= 2;
}

signed main() {
#ifdef LC
	assert(freopen("input.txt", "r", stdin));
#endif
	ios::sync_with_stdio(0); cin.tie(0); 
	cin >> n >> k;
	for (int i = 0; i < n; ++i) {
		cin >> p[i].x >> p[i].y;
		int nx = p[i].x + p[i].y;
		int ny = p[i].x - p[i].y;
		p[i].x = nx;
		p[i].y = ny;
		// cout << i << " " << nx << " " << ny << endl;
	}
	sort(p, p + n);
	int lef = 0, rig = (int)2e9;
	while (rig - lef > 1) {
		int mid = (lef + rig) / 2;
		if (query(mid) < k) {
			lef = mid;
		} else {
			rig = mid;
		}
	}
	int c = lef;
	vector<int> answer;
	vector<tuple<int, int, int>> scan;
	for (int i = 0; i < n; ++i) {
		scan.emplace_back(p[i].x - c,  OPEN, p[i].y);
		scan.emplace_back(p[i].x,     QUERY, p[i].y);
		scan.emplace_back(p[i].x + c, CLOSE, p[i].y);
	}
	sort(all(scan));
	q.clear();
	for (auto e : scan) {
		int x, t, y;
		tie(x, t, y) = e;
		if (t == OPEN) {
			q.insert(mp(y, x + c));
		} else if (t == CLOSE) {
			q.erase(mp(y, x - c));
		} else {
			auto le = q.lower_bound(mp(y - c, -INF)),
				 ri = q.upper_bound(mp(y + c, +INF));
			for (auto it = le; it != ri; ++it) {
				int px = it->y, py = it->x, d = max(abs(px - x), abs(py - y));
				if (!d) {
					continue;
				}
				answer.push_back(d);
			}
		}
	}
	sort(all(answer));
	for (int i = 0; i + 1 < (int)answer.size(); i += 2) {
		assert(answer[i] == answer[i + 1]);
	}
	for (int i = 0; i < k; ++i) {
		if (2 * i < (int)answer.size()) {
			cout << answer[2 * i] << "\n";
		} else {
			cout << rig << "\n";
		}
	}
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 103 ms 7052 KB Output is correct
2 Correct 102 ms 7048 KB Output is correct
3 Incorrect 86 ms 6400 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3890 ms 49340 KB Output is correct
2 Correct 3989 ms 48248 KB Output is correct
3 Correct 109 ms 6980 KB Output is correct
4 Correct 3884 ms 49328 KB Output is correct
5 Correct 4436 ms 49184 KB Output is correct
6 Correct 4409 ms 47808 KB Output is correct
7 Correct 4341 ms 52060 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5022 ms 51400 KB Output is correct
2 Correct 5485 ms 50972 KB Output is correct
3 Incorrect 1 ms 204 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5022 ms 51400 KB Output is correct
2 Correct 5485 ms 50972 KB Output is correct
3 Incorrect 1 ms 204 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 103 ms 7052 KB Output is correct
2 Correct 102 ms 7048 KB Output is correct
3 Incorrect 86 ms 6400 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 103 ms 7052 KB Output is correct
2 Correct 102 ms 7048 KB Output is correct
3 Incorrect 86 ms 6400 KB Output isn't correct
4 Halted 0 ms 0 KB -