Submission #734561

# Submission time Handle Problem Language Result Execution time Memory
734561 2023-05-02T16:00:35 Z hollwo_pelw Circle selection (APIO18_circle_selection) C++17
100 / 100
1582 ms 60920 KB
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/trie_policy.hpp>
// #include <ext/rope>

using namespace std;
// using namespace __gnu_cxx;
// using namespace __gnu_pbds;

void Hollwo_Pelw();

signed main(){
#ifndef hollwo_pelw_local
	if (fopen(".inp", "r"))
		assert(freopen(".inp", "r", stdin)), assert(freopen(".out", "w", stdout));
#else
	using namespace chrono;
	auto start = steady_clock::now();
#endif
	cin.tie(0), cout.tie(0) -> sync_with_stdio(0);
	int testcases = 1;
	// cin >> testcases;
	for (int test = 1; test <= testcases; test++){
		// cout << "Case #" << test << ": ";
		Hollwo_Pelw();
	}
#ifdef hollwo_pelw_local
	auto end = steady_clock::now();
	cout << "\nExecution time : " << duration_cast<milliseconds> (end - start).count() << "[ms]" << endl;
#endif
}

const int N = 3e5 + 5;

struct circle_t {
	int x, y, r;
} a[N];
int n, len, res[N];

bool intersect(const circle_t &a, const circle_t &b) {
	return 1ll * (a.x - b.x) * (a.x - b.x) + 1ll * (a.y - b.y) * (a.y - b.y) <= 1ll * (a.r + b.r) * (a.r + b.r);
}

struct cmp {
	bool operator () (const int &i, const int &j) const {
		return a[i].r > a[j].r || (a[i].r == a[j].r && i < j);
	}
};
set<int, cmp> st;
map<int, vector<pair<int, int>>> grid;

void rebuild() {
	grid.clear();
	for (auto p : st) {
		int x = a[p].x / len, y = a[p].y / len;
		// add (x, y, p)
		grid[x].emplace_back(y, p);
	}
	for (auto &[x, vy] : grid)
		sort(vy.begin(), vy.end());
}

void Hollwo_Pelw(){
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> a[i].x >> a[i].y >> a[i].r;
		a[i].x += 1e9, a[i].y += 1e9, st.insert(i);
	}

	while (!st.empty()) {
		auto p = *st.begin();
		if ((int) st.size() == n || a[p].r * 2 < len)
			len = a[p].r, rebuild();

		int x = a[p].x / len, y = a[p].y / len;

		for (auto itx = grid.lower_bound(x - 2); itx != grid.end() && itx -> first <= x + 2; itx ++) {
			auto &vy = itx -> second;
			for (auto ity = lower_bound(vy.begin(), vy.end(), pair<int, int>{y - 2, 0}); ity != vy.end() && ity -> first <= y + 2; ity ++) {

				int q = ity -> second;
				if (!res[q] && intersect(a[p], a[q]))
					res[q] = p, st.erase(q);
			}
		}
	}

	for (int i = 1; i <= n; i++) {
		cout << res[i] << " \n"[i == n];
	}
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 312 KB Output is correct
6 Correct 1 ms 328 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 2 ms 340 KB Output is correct
17 Correct 2 ms 340 KB Output is correct
18 Correct 2 ms 340 KB Output is correct
19 Correct 6 ms 816 KB Output is correct
20 Correct 7 ms 852 KB Output is correct
21 Correct 5 ms 852 KB Output is correct
22 Correct 8 ms 1108 KB Output is correct
23 Correct 9 ms 852 KB Output is correct
24 Correct 8 ms 1108 KB Output is correct
25 Correct 7 ms 1320 KB Output is correct
26 Correct 8 ms 1104 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 802 ms 28232 KB Output is correct
2 Correct 805 ms 28360 KB Output is correct
3 Correct 756 ms 30036 KB Output is correct
4 Correct 629 ms 29344 KB Output is correct
5 Correct 645 ms 30172 KB Output is correct
6 Correct 1022 ms 42636 KB Output is correct
7 Correct 769 ms 31884 KB Output is correct
8 Correct 813 ms 33948 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 267 ms 11996 KB Output is correct
3 Correct 1098 ms 35440 KB Output is correct
4 Correct 1136 ms 35528 KB Output is correct
5 Correct 1091 ms 31948 KB Output is correct
6 Correct 498 ms 17684 KB Output is correct
7 Correct 268 ms 9848 KB Output is correct
8 Correct 24 ms 2840 KB Output is correct
9 Correct 1582 ms 34024 KB Output is correct
10 Correct 1117 ms 31980 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 777 ms 40364 KB Output is correct
2 Correct 793 ms 60920 KB Output is correct
3 Correct 593 ms 32552 KB Output is correct
4 Correct 790 ms 58924 KB Output is correct
5 Correct 828 ms 60532 KB Output is correct
6 Correct 605 ms 31624 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 312 KB Output is correct
6 Correct 1 ms 328 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 2 ms 340 KB Output is correct
17 Correct 2 ms 340 KB Output is correct
18 Correct 2 ms 340 KB Output is correct
19 Correct 6 ms 816 KB Output is correct
20 Correct 7 ms 852 KB Output is correct
21 Correct 5 ms 852 KB Output is correct
22 Correct 8 ms 1108 KB Output is correct
23 Correct 9 ms 852 KB Output is correct
24 Correct 8 ms 1108 KB Output is correct
25 Correct 7 ms 1320 KB Output is correct
26 Correct 8 ms 1104 KB Output is correct
27 Correct 11 ms 1364 KB Output is correct
28 Correct 11 ms 1476 KB Output is correct
29 Correct 10 ms 1364 KB Output is correct
30 Correct 15 ms 1488 KB Output is correct
31 Correct 21 ms 1880 KB Output is correct
32 Correct 17 ms 1876 KB Output is correct
33 Correct 161 ms 11112 KB Output is correct
34 Correct 170 ms 11108 KB Output is correct
35 Correct 143 ms 10552 KB Output is correct
36 Correct 329 ms 14388 KB Output is correct
37 Correct 381 ms 14212 KB Output is correct
38 Correct 358 ms 13232 KB Output is correct
39 Correct 450 ms 9712 KB Output is correct
40 Correct 428 ms 9616 KB Output is correct
41 Correct 419 ms 9460 KB Output is correct
42 Correct 121 ms 10188 KB Output is correct
43 Correct 211 ms 20308 KB Output is correct
44 Correct 208 ms 20344 KB Output is correct
45 Correct 236 ms 20292 KB Output is correct
46 Correct 269 ms 20324 KB Output is correct
47 Correct 243 ms 20380 KB Output is correct
48 Correct 215 ms 20392 KB Output is correct
49 Correct 285 ms 20396 KB Output is correct
50 Correct 232 ms 20348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 312 KB Output is correct
6 Correct 1 ms 328 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 2 ms 340 KB Output is correct
17 Correct 2 ms 340 KB Output is correct
18 Correct 2 ms 340 KB Output is correct
19 Correct 6 ms 816 KB Output is correct
20 Correct 7 ms 852 KB Output is correct
21 Correct 5 ms 852 KB Output is correct
22 Correct 8 ms 1108 KB Output is correct
23 Correct 9 ms 852 KB Output is correct
24 Correct 8 ms 1108 KB Output is correct
25 Correct 7 ms 1320 KB Output is correct
26 Correct 8 ms 1104 KB Output is correct
27 Correct 802 ms 28232 KB Output is correct
28 Correct 805 ms 28360 KB Output is correct
29 Correct 756 ms 30036 KB Output is correct
30 Correct 629 ms 29344 KB Output is correct
31 Correct 645 ms 30172 KB Output is correct
32 Correct 1022 ms 42636 KB Output is correct
33 Correct 769 ms 31884 KB Output is correct
34 Correct 813 ms 33948 KB Output is correct
35 Correct 1 ms 212 KB Output is correct
36 Correct 267 ms 11996 KB Output is correct
37 Correct 1098 ms 35440 KB Output is correct
38 Correct 1136 ms 35528 KB Output is correct
39 Correct 1091 ms 31948 KB Output is correct
40 Correct 498 ms 17684 KB Output is correct
41 Correct 268 ms 9848 KB Output is correct
42 Correct 24 ms 2840 KB Output is correct
43 Correct 1582 ms 34024 KB Output is correct
44 Correct 1117 ms 31980 KB Output is correct
45 Correct 777 ms 40364 KB Output is correct
46 Correct 793 ms 60920 KB Output is correct
47 Correct 593 ms 32552 KB Output is correct
48 Correct 790 ms 58924 KB Output is correct
49 Correct 828 ms 60532 KB Output is correct
50 Correct 605 ms 31624 KB Output is correct
51 Correct 11 ms 1364 KB Output is correct
52 Correct 11 ms 1476 KB Output is correct
53 Correct 10 ms 1364 KB Output is correct
54 Correct 15 ms 1488 KB Output is correct
55 Correct 21 ms 1880 KB Output is correct
56 Correct 17 ms 1876 KB Output is correct
57 Correct 161 ms 11112 KB Output is correct
58 Correct 170 ms 11108 KB Output is correct
59 Correct 143 ms 10552 KB Output is correct
60 Correct 329 ms 14388 KB Output is correct
61 Correct 381 ms 14212 KB Output is correct
62 Correct 358 ms 13232 KB Output is correct
63 Correct 450 ms 9712 KB Output is correct
64 Correct 428 ms 9616 KB Output is correct
65 Correct 419 ms 9460 KB Output is correct
66 Correct 121 ms 10188 KB Output is correct
67 Correct 211 ms 20308 KB Output is correct
68 Correct 208 ms 20344 KB Output is correct
69 Correct 236 ms 20292 KB Output is correct
70 Correct 269 ms 20324 KB Output is correct
71 Correct 243 ms 20380 KB Output is correct
72 Correct 215 ms 20392 KB Output is correct
73 Correct 285 ms 20396 KB Output is correct
74 Correct 232 ms 20348 KB Output is correct
75 Correct 933 ms 31816 KB Output is correct
76 Correct 807 ms 30304 KB Output is correct
77 Correct 654 ms 32496 KB Output is correct
78 Correct 737 ms 32296 KB Output is correct
79 Correct 1112 ms 30436 KB Output is correct
80 Correct 744 ms 32384 KB Output is correct
81 Correct 1188 ms 35924 KB Output is correct
82 Correct 1315 ms 37540 KB Output is correct
83 Correct 1242 ms 37376 KB Output is correct
84 Correct 982 ms 34504 KB Output is correct
85 Correct 1111 ms 36500 KB Output is correct
86 Correct 1185 ms 38276 KB Output is correct
87 Correct 947 ms 31956 KB Output is correct
88 Correct 1358 ms 28440 KB Output is correct
89 Correct 1319 ms 29132 KB Output is correct
90 Correct 1393 ms 28544 KB Output is correct
91 Correct 1399 ms 28540 KB Output is correct
92 Correct 1401 ms 28520 KB Output is correct
93 Correct 1057 ms 60460 KB Output is correct
94 Correct 537 ms 30276 KB Output is correct
95 Correct 1092 ms 60544 KB Output is correct
96 Correct 1141 ms 59576 KB Output is correct
97 Correct 584 ms 29320 KB Output is correct
98 Correct 1041 ms 43972 KB Output is correct
99 Correct 1097 ms 60712 KB Output is correct
100 Correct 817 ms 60788 KB Output is correct
101 Correct 1016 ms 37908 KB Output is correct
102 Correct 1165 ms 59536 KB Output is correct
103 Correct 650 ms 29036 KB Output is correct
104 Correct 1220 ms 60584 KB Output is correct
105 Correct 482 ms 30672 KB Output is correct
106 Correct 798 ms 54404 KB Output is correct
107 Correct 788 ms 54440 KB Output is correct
108 Correct 838 ms 54456 KB Output is correct
109 Correct 823 ms 54452 KB Output is correct
110 Correct 855 ms 54348 KB Output is correct
111 Correct 775 ms 54332 KB Output is correct
112 Correct 757 ms 54432 KB Output is correct
113 Correct 780 ms 54404 KB Output is correct
114 Correct 801 ms 54224 KB Output is correct
115 Correct 761 ms 54436 KB Output is correct
116 Correct 823 ms 59228 KB Output is correct