Submission #258973

# Submission time Handle Problem Language Result Execution time Memory
258973 2020-08-06T22:18:13 Z amoo_safar Circle selection (APIO18_circle_selection) C++17
100 / 100
868 ms 29772 KB
// Null
#include <bits/stdc++.h>

#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
 
#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define debug(x) cerr << #x << " : " << x << '\n'
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef string str;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;

const ll Mod = 1000000007LL;
const int N = 3e5 + 10;
const int Inf = 2e9;

int n, x[N], y[N], r[N];
int mk[N];

vector<pii> V[N];
vector<int> U, X, Y;

void Build(int L){
	for(int i = 0; i < (int) U.size(); i++) V[i].clear();
	U.clear();

	for(int i : X){
		if(mk[i]) continue;
		U.pb(x[i] / L);
	}
	//sort(all(U));
	U.resize(unique(all(U)) - U.begin() );
	for(int i : Y)
		if(!mk[i])
			V[lower_bound(all(U), x[i] / L) - U.begin()].pb({y[i] / L, i});
	for(int i = 0; i < (int) U.size(); i++)
		sort(all(V[i]));
}

int main(){
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n;
	for(int i = 1; i <= n; i++){
		cin >> x[i] >> y[i] >> r[i];
		X.pb(i);
		Y.pb(i);
	}
	vector<int> I(n); iota(all(I), 1);
	sort(all(I), [&](int i, int j){
		return (r[i] == r[j] ? i < j : r[i] > r[j]);
	});
	sort(all(X), [&](int i, int j){
		return x[i] < x[j];
	});
	sort(all(Y), [&](int i, int j){
		return y[i] < y[j];
	});

	int L = r[I[0]];
	Build(L);
	for(auto id : I){
		if(mk[id]) continue;
		if(L >= 3*r[id]) Build(L = r[id]);

		int i = x[id] / L;
		int j = y[id] / L;

		int nei;
		for(int pos = lower_bound(all(U), i - 2) - U.begin(); pos < (int) U.size() && U[pos] <= i + 2; pos ++){

			for(int posj = lower_bound(all(V[pos]), pii(j - 2, -1)) - V[pos].begin(); posj < (int) V[pos].size() && V[pos][posj].F <= j + 2; posj ++){
				nei = V[pos][posj].S;
				if(mk[nei]) continue;
				if(1ll*(x[id] - x[nei])*(x[id] - x[nei]) + 1ll*(y[id] - y[nei])*(y[id] - y[nei]) <= 1ll*(r[id] + r[nei])*(r[id] + r[nei]) ){
					mk[nei] = id;
				}
			}
		}
	}
	
	for(int i = 1; i <= n; i++) cout << mk[i] << ' ';
	cout << '\n';
	return 0;
}
/*
11
9 9 2
13 2 1
11 8 2
3 3 2
3 12 1
12 14 1
9 8 5
2 8 2
5 2 1
14 4 2
14 14 1

*/
# Verdict Execution time Memory Grader output
1 Correct 5 ms 7424 KB Output is correct
2 Correct 7 ms 7424 KB Output is correct
3 Correct 5 ms 7424 KB Output is correct
4 Correct 6 ms 7424 KB Output is correct
5 Correct 5 ms 7424 KB Output is correct
6 Correct 5 ms 7424 KB Output is correct
7 Correct 6 ms 7424 KB Output is correct
8 Correct 6 ms 7552 KB Output is correct
9 Correct 5 ms 7424 KB Output is correct
10 Correct 5 ms 7424 KB Output is correct
11 Correct 6 ms 7424 KB Output is correct
12 Correct 5 ms 7424 KB Output is correct
13 Correct 7 ms 7424 KB Output is correct
14 Correct 5 ms 7424 KB Output is correct
15 Correct 5 ms 7400 KB Output is correct
16 Correct 5 ms 7424 KB Output is correct
17 Correct 5 ms 7424 KB Output is correct
18 Correct 8 ms 7424 KB Output is correct
19 Correct 10 ms 7808 KB Output is correct
20 Correct 13 ms 7808 KB Output is correct
21 Correct 10 ms 7912 KB Output is correct
22 Correct 13 ms 7808 KB Output is correct
23 Correct 12 ms 7808 KB Output is correct
24 Correct 11 ms 7808 KB Output is correct
25 Correct 11 ms 7852 KB Output is correct
26 Correct 12 ms 7808 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 281 ms 23356 KB Output is correct
2 Correct 282 ms 24660 KB Output is correct
3 Correct 269 ms 25396 KB Output is correct
4 Correct 286 ms 23400 KB Output is correct
5 Correct 313 ms 24388 KB Output is correct
6 Correct 442 ms 25896 KB Output is correct
7 Correct 329 ms 24656 KB Output is correct
8 Correct 334 ms 24788 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 7424 KB Output is correct
2 Correct 157 ms 14676 KB Output is correct
3 Correct 566 ms 25156 KB Output is correct
4 Correct 566 ms 25040 KB Output is correct
5 Correct 554 ms 24912 KB Output is correct
6 Correct 227 ms 17092 KB Output is correct
7 Correct 117 ms 12396 KB Output is correct
8 Correct 29 ms 8832 KB Output is correct
9 Correct 556 ms 26196 KB Output is correct
10 Correct 509 ms 26048 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 550 ms 25452 KB Output is correct
2 Correct 514 ms 29772 KB Output is correct
3 Correct 325 ms 23372 KB Output is correct
4 Correct 558 ms 29136 KB Output is correct
5 Correct 530 ms 29524 KB Output is correct
6 Correct 332 ms 22500 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 7424 KB Output is correct
2 Correct 7 ms 7424 KB Output is correct
3 Correct 5 ms 7424 KB Output is correct
4 Correct 6 ms 7424 KB Output is correct
5 Correct 5 ms 7424 KB Output is correct
6 Correct 5 ms 7424 KB Output is correct
7 Correct 6 ms 7424 KB Output is correct
8 Correct 6 ms 7552 KB Output is correct
9 Correct 5 ms 7424 KB Output is correct
10 Correct 5 ms 7424 KB Output is correct
11 Correct 6 ms 7424 KB Output is correct
12 Correct 5 ms 7424 KB Output is correct
13 Correct 7 ms 7424 KB Output is correct
14 Correct 5 ms 7424 KB Output is correct
15 Correct 5 ms 7400 KB Output is correct
16 Correct 5 ms 7424 KB Output is correct
17 Correct 5 ms 7424 KB Output is correct
18 Correct 8 ms 7424 KB Output is correct
19 Correct 10 ms 7808 KB Output is correct
20 Correct 13 ms 7808 KB Output is correct
21 Correct 10 ms 7912 KB Output is correct
22 Correct 13 ms 7808 KB Output is correct
23 Correct 12 ms 7808 KB Output is correct
24 Correct 11 ms 7808 KB Output is correct
25 Correct 11 ms 7852 KB Output is correct
26 Correct 12 ms 7808 KB Output is correct
27 Correct 16 ms 8320 KB Output is correct
28 Correct 14 ms 8192 KB Output is correct
29 Correct 14 ms 8192 KB Output is correct
30 Correct 19 ms 8192 KB Output is correct
31 Correct 17 ms 8192 KB Output is correct
32 Correct 18 ms 8192 KB Output is correct
33 Correct 112 ms 14052 KB Output is correct
34 Correct 124 ms 14312 KB Output is correct
35 Correct 113 ms 14316 KB Output is correct
36 Correct 160 ms 14988 KB Output is correct
37 Correct 165 ms 13672 KB Output is correct
38 Correct 158 ms 13416 KB Output is correct
39 Correct 244 ms 14048 KB Output is correct
40 Correct 251 ms 14688 KB Output is correct
41 Correct 256 ms 14692 KB Output is correct
42 Correct 98 ms 13292 KB Output is correct
43 Correct 141 ms 14956 KB Output is correct
44 Correct 136 ms 14952 KB Output is correct
45 Correct 136 ms 14952 KB Output is correct
46 Correct 125 ms 15076 KB Output is correct
47 Correct 139 ms 14956 KB Output is correct
48 Correct 135 ms 14952 KB Output is correct
49 Correct 128 ms 14900 KB Output is correct
50 Correct 122 ms 14948 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 7424 KB Output is correct
2 Correct 7 ms 7424 KB Output is correct
3 Correct 5 ms 7424 KB Output is correct
4 Correct 6 ms 7424 KB Output is correct
5 Correct 5 ms 7424 KB Output is correct
6 Correct 5 ms 7424 KB Output is correct
7 Correct 6 ms 7424 KB Output is correct
8 Correct 6 ms 7552 KB Output is correct
9 Correct 5 ms 7424 KB Output is correct
10 Correct 5 ms 7424 KB Output is correct
11 Correct 6 ms 7424 KB Output is correct
12 Correct 5 ms 7424 KB Output is correct
13 Correct 7 ms 7424 KB Output is correct
14 Correct 5 ms 7424 KB Output is correct
15 Correct 5 ms 7400 KB Output is correct
16 Correct 5 ms 7424 KB Output is correct
17 Correct 5 ms 7424 KB Output is correct
18 Correct 8 ms 7424 KB Output is correct
19 Correct 10 ms 7808 KB Output is correct
20 Correct 13 ms 7808 KB Output is correct
21 Correct 10 ms 7912 KB Output is correct
22 Correct 13 ms 7808 KB Output is correct
23 Correct 12 ms 7808 KB Output is correct
24 Correct 11 ms 7808 KB Output is correct
25 Correct 11 ms 7852 KB Output is correct
26 Correct 12 ms 7808 KB Output is correct
27 Correct 281 ms 23356 KB Output is correct
28 Correct 282 ms 24660 KB Output is correct
29 Correct 269 ms 25396 KB Output is correct
30 Correct 286 ms 23400 KB Output is correct
31 Correct 313 ms 24388 KB Output is correct
32 Correct 442 ms 25896 KB Output is correct
33 Correct 329 ms 24656 KB Output is correct
34 Correct 334 ms 24788 KB Output is correct
35 Correct 6 ms 7424 KB Output is correct
36 Correct 157 ms 14676 KB Output is correct
37 Correct 566 ms 25156 KB Output is correct
38 Correct 566 ms 25040 KB Output is correct
39 Correct 554 ms 24912 KB Output is correct
40 Correct 227 ms 17092 KB Output is correct
41 Correct 117 ms 12396 KB Output is correct
42 Correct 29 ms 8832 KB Output is correct
43 Correct 556 ms 26196 KB Output is correct
44 Correct 509 ms 26048 KB Output is correct
45 Correct 550 ms 25452 KB Output is correct
46 Correct 514 ms 29772 KB Output is correct
47 Correct 325 ms 23372 KB Output is correct
48 Correct 558 ms 29136 KB Output is correct
49 Correct 530 ms 29524 KB Output is correct
50 Correct 332 ms 22500 KB Output is correct
51 Correct 16 ms 8320 KB Output is correct
52 Correct 14 ms 8192 KB Output is correct
53 Correct 14 ms 8192 KB Output is correct
54 Correct 19 ms 8192 KB Output is correct
55 Correct 17 ms 8192 KB Output is correct
56 Correct 18 ms 8192 KB Output is correct
57 Correct 112 ms 14052 KB Output is correct
58 Correct 124 ms 14312 KB Output is correct
59 Correct 113 ms 14316 KB Output is correct
60 Correct 160 ms 14988 KB Output is correct
61 Correct 165 ms 13672 KB Output is correct
62 Correct 158 ms 13416 KB Output is correct
63 Correct 244 ms 14048 KB Output is correct
64 Correct 251 ms 14688 KB Output is correct
65 Correct 256 ms 14692 KB Output is correct
66 Correct 98 ms 13292 KB Output is correct
67 Correct 141 ms 14956 KB Output is correct
68 Correct 136 ms 14952 KB Output is correct
69 Correct 136 ms 14952 KB Output is correct
70 Correct 125 ms 15076 KB Output is correct
71 Correct 139 ms 14956 KB Output is correct
72 Correct 135 ms 14952 KB Output is correct
73 Correct 128 ms 14900 KB Output is correct
74 Correct 122 ms 14948 KB Output is correct
75 Correct 343 ms 24784 KB Output is correct
76 Correct 344 ms 24572 KB Output is correct
77 Correct 335 ms 22932 KB Output is correct
78 Correct 364 ms 22664 KB Output is correct
79 Correct 340 ms 23420 KB Output is correct
80 Correct 340 ms 22724 KB Output is correct
81 Correct 609 ms 25172 KB Output is correct
82 Correct 593 ms 25164 KB Output is correct
83 Correct 576 ms 25420 KB Output is correct
84 Correct 544 ms 24916 KB Output is correct
85 Correct 550 ms 25172 KB Output is correct
86 Correct 640 ms 25188 KB Output is correct
87 Correct 552 ms 25932 KB Output is correct
88 Correct 760 ms 26832 KB Output is correct
89 Correct 828 ms 29224 KB Output is correct
90 Correct 868 ms 26724 KB Output is correct
91 Correct 764 ms 28988 KB Output is correct
92 Correct 769 ms 26708 KB Output is correct
93 Correct 555 ms 29652 KB Output is correct
94 Correct 382 ms 24136 KB Output is correct
95 Correct 568 ms 29644 KB Output is correct
96 Correct 577 ms 29756 KB Output is correct
97 Correct 512 ms 24552 KB Output is correct
98 Correct 473 ms 25688 KB Output is correct
99 Correct 619 ms 29616 KB Output is correct
100 Correct 544 ms 29176 KB Output is correct
101 Correct 527 ms 23640 KB Output is correct
102 Correct 638 ms 27924 KB Output is correct
103 Correct 471 ms 23116 KB Output is correct
104 Correct 581 ms 28504 KB Output is correct
105 Correct 324 ms 23432 KB Output is correct
106 Correct 438 ms 26320 KB Output is correct
107 Correct 413 ms 26580 KB Output is correct
108 Correct 447 ms 26356 KB Output is correct
109 Correct 414 ms 26452 KB Output is correct
110 Correct 426 ms 26460 KB Output is correct
111 Correct 443 ms 26316 KB Output is correct
112 Correct 414 ms 26452 KB Output is correct
113 Correct 427 ms 26388 KB Output is correct
114 Correct 447 ms 26328 KB Output is correct
115 Correct 409 ms 26316 KB Output is correct
116 Correct 419 ms 27772 KB Output is correct