Submission #258970

# Submission time Handle Problem Language Result Execution time Memory
258970 2020-08-06T22:15:26 Z amoo_safar Circle selection (APIO18_circle_selection) C++17
100 / 100
1010 ms 31316 KB
// Null
#include <bits/stdc++.h>
 
#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 >= 2*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 5 ms 7424 KB Output is correct
3 Correct 7 ms 7424 KB Output is correct
4 Correct 5 ms 7424 KB Output is correct
5 Correct 5 ms 7424 KB Output is correct
6 Correct 4 ms 7424 KB Output is correct
7 Correct 4 ms 7424 KB Output is correct
8 Correct 5 ms 7424 KB Output is correct
9 Correct 5 ms 7424 KB Output is correct
10 Correct 5 ms 7424 KB Output is correct
11 Correct 5 ms 7424 KB Output is correct
12 Correct 5 ms 7424 KB Output is correct
13 Correct 5 ms 7424 KB Output is correct
14 Correct 5 ms 7424 KB Output is correct
15 Correct 5 ms 7424 KB Output is correct
16 Correct 5 ms 7424 KB Output is correct
17 Correct 5 ms 7424 KB Output is correct
18 Correct 5 ms 7424 KB Output is correct
19 Correct 9 ms 7808 KB Output is correct
20 Correct 9 ms 7808 KB Output is correct
21 Correct 9 ms 7808 KB Output is correct
22 Correct 11 ms 7808 KB Output is correct
23 Correct 11 ms 7752 KB Output is correct
24 Correct 11 ms 7808 KB Output is correct
25 Correct 11 ms 7808 KB Output is correct
26 Correct 10 ms 7808 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 245 ms 21844 KB Output is correct
2 Correct 237 ms 22860 KB Output is correct
3 Correct 244 ms 23632 KB Output is correct
4 Correct 240 ms 21612 KB Output is correct
5 Correct 272 ms 22604 KB Output is correct
6 Correct 401 ms 27468 KB Output is correct
7 Correct 286 ms 26324 KB Output is correct
8 Correct 323 ms 26324 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 7424 KB Output is correct
2 Correct 161 ms 13032 KB Output is correct
3 Correct 588 ms 27092 KB Output is correct
4 Correct 628 ms 26964 KB Output is correct
5 Correct 530 ms 27348 KB Output is correct
6 Correct 235 ms 19172 KB Output is correct
7 Correct 114 ms 14052 KB Output is correct
8 Correct 24 ms 8928 KB Output is correct
9 Correct 577 ms 28764 KB Output is correct
10 Correct 478 ms 28384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 458 ms 23760 KB Output is correct
2 Correct 529 ms 31316 KB Output is correct
3 Correct 293 ms 25036 KB Output is correct
4 Correct 499 ms 30672 KB Output is correct
5 Correct 492 ms 31316 KB Output is correct
6 Correct 279 ms 24016 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 7424 KB Output is correct
2 Correct 5 ms 7424 KB Output is correct
3 Correct 7 ms 7424 KB Output is correct
4 Correct 5 ms 7424 KB Output is correct
5 Correct 5 ms 7424 KB Output is correct
6 Correct 4 ms 7424 KB Output is correct
7 Correct 4 ms 7424 KB Output is correct
8 Correct 5 ms 7424 KB Output is correct
9 Correct 5 ms 7424 KB Output is correct
10 Correct 5 ms 7424 KB Output is correct
11 Correct 5 ms 7424 KB Output is correct
12 Correct 5 ms 7424 KB Output is correct
13 Correct 5 ms 7424 KB Output is correct
14 Correct 5 ms 7424 KB Output is correct
15 Correct 5 ms 7424 KB Output is correct
16 Correct 5 ms 7424 KB Output is correct
17 Correct 5 ms 7424 KB Output is correct
18 Correct 5 ms 7424 KB Output is correct
19 Correct 9 ms 7808 KB Output is correct
20 Correct 9 ms 7808 KB Output is correct
21 Correct 9 ms 7808 KB Output is correct
22 Correct 11 ms 7808 KB Output is correct
23 Correct 11 ms 7752 KB Output is correct
24 Correct 11 ms 7808 KB Output is correct
25 Correct 11 ms 7808 KB Output is correct
26 Correct 10 ms 7808 KB Output is correct
27 Correct 15 ms 8064 KB Output is correct
28 Correct 13 ms 8064 KB Output is correct
29 Correct 12 ms 8064 KB Output is correct
30 Correct 17 ms 8056 KB Output is correct
31 Correct 18 ms 8064 KB Output is correct
32 Correct 18 ms 8088 KB Output is correct
33 Correct 97 ms 12268 KB Output is correct
34 Correct 100 ms 12520 KB Output is correct
35 Correct 101 ms 12552 KB Output is correct
36 Correct 162 ms 13168 KB Output is correct
37 Correct 162 ms 15464 KB Output is correct
38 Correct 180 ms 15464 KB Output is correct
39 Correct 305 ms 14952 KB Output is correct
40 Correct 307 ms 15076 KB Output is correct
41 Correct 305 ms 14952 KB Output is correct
42 Correct 83 ms 14060 KB Output is correct
43 Correct 114 ms 16748 KB Output is correct
44 Correct 115 ms 16876 KB Output is correct
45 Correct 114 ms 16748 KB Output is correct
46 Correct 115 ms 16876 KB Output is correct
47 Correct 117 ms 16752 KB Output is correct
48 Correct 116 ms 16748 KB Output is correct
49 Correct 115 ms 16748 KB Output is correct
50 Correct 114 ms 16744 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 7424 KB Output is correct
2 Correct 5 ms 7424 KB Output is correct
3 Correct 7 ms 7424 KB Output is correct
4 Correct 5 ms 7424 KB Output is correct
5 Correct 5 ms 7424 KB Output is correct
6 Correct 4 ms 7424 KB Output is correct
7 Correct 4 ms 7424 KB Output is correct
8 Correct 5 ms 7424 KB Output is correct
9 Correct 5 ms 7424 KB Output is correct
10 Correct 5 ms 7424 KB Output is correct
11 Correct 5 ms 7424 KB Output is correct
12 Correct 5 ms 7424 KB Output is correct
13 Correct 5 ms 7424 KB Output is correct
14 Correct 5 ms 7424 KB Output is correct
15 Correct 5 ms 7424 KB Output is correct
16 Correct 5 ms 7424 KB Output is correct
17 Correct 5 ms 7424 KB Output is correct
18 Correct 5 ms 7424 KB Output is correct
19 Correct 9 ms 7808 KB Output is correct
20 Correct 9 ms 7808 KB Output is correct
21 Correct 9 ms 7808 KB Output is correct
22 Correct 11 ms 7808 KB Output is correct
23 Correct 11 ms 7752 KB Output is correct
24 Correct 11 ms 7808 KB Output is correct
25 Correct 11 ms 7808 KB Output is correct
26 Correct 10 ms 7808 KB Output is correct
27 Correct 245 ms 21844 KB Output is correct
28 Correct 237 ms 22860 KB Output is correct
29 Correct 244 ms 23632 KB Output is correct
30 Correct 240 ms 21612 KB Output is correct
31 Correct 272 ms 22604 KB Output is correct
32 Correct 401 ms 27468 KB Output is correct
33 Correct 286 ms 26324 KB Output is correct
34 Correct 323 ms 26324 KB Output is correct
35 Correct 5 ms 7424 KB Output is correct
36 Correct 161 ms 13032 KB Output is correct
37 Correct 588 ms 27092 KB Output is correct
38 Correct 628 ms 26964 KB Output is correct
39 Correct 530 ms 27348 KB Output is correct
40 Correct 235 ms 19172 KB Output is correct
41 Correct 114 ms 14052 KB Output is correct
42 Correct 24 ms 8928 KB Output is correct
43 Correct 577 ms 28764 KB Output is correct
44 Correct 478 ms 28384 KB Output is correct
45 Correct 458 ms 23760 KB Output is correct
46 Correct 529 ms 31316 KB Output is correct
47 Correct 293 ms 25036 KB Output is correct
48 Correct 499 ms 30672 KB Output is correct
49 Correct 492 ms 31316 KB Output is correct
50 Correct 279 ms 24016 KB Output is correct
51 Correct 15 ms 8064 KB Output is correct
52 Correct 13 ms 8064 KB Output is correct
53 Correct 12 ms 8064 KB Output is correct
54 Correct 17 ms 8056 KB Output is correct
55 Correct 18 ms 8064 KB Output is correct
56 Correct 18 ms 8088 KB Output is correct
57 Correct 97 ms 12268 KB Output is correct
58 Correct 100 ms 12520 KB Output is correct
59 Correct 101 ms 12552 KB Output is correct
60 Correct 162 ms 13168 KB Output is correct
61 Correct 162 ms 15464 KB Output is correct
62 Correct 180 ms 15464 KB Output is correct
63 Correct 305 ms 14952 KB Output is correct
64 Correct 307 ms 15076 KB Output is correct
65 Correct 305 ms 14952 KB Output is correct
66 Correct 83 ms 14060 KB Output is correct
67 Correct 114 ms 16748 KB Output is correct
68 Correct 115 ms 16876 KB Output is correct
69 Correct 114 ms 16748 KB Output is correct
70 Correct 115 ms 16876 KB Output is correct
71 Correct 117 ms 16752 KB Output is correct
72 Correct 116 ms 16748 KB Output is correct
73 Correct 115 ms 16748 KB Output is correct
74 Correct 114 ms 16744 KB Output is correct
75 Correct 322 ms 26316 KB Output is correct
76 Correct 298 ms 26224 KB Output is correct
77 Correct 297 ms 24532 KB Output is correct
78 Correct 301 ms 24140 KB Output is correct
79 Correct 329 ms 24564 KB Output is correct
80 Correct 317 ms 24232 KB Output is correct
81 Correct 606 ms 26580 KB Output is correct
82 Correct 588 ms 26692 KB Output is correct
83 Correct 618 ms 26708 KB Output is correct
84 Correct 624 ms 26324 KB Output is correct
85 Correct 588 ms 26448 KB Output is correct
86 Correct 602 ms 26572 KB Output is correct
87 Correct 534 ms 27132 KB Output is correct
88 Correct 1010 ms 29896 KB Output is correct
89 Correct 963 ms 29636 KB Output is correct
90 Correct 1008 ms 29892 KB Output is correct
91 Correct 988 ms 29672 KB Output is correct
92 Correct 1000 ms 29656 KB Output is correct
93 Correct 578 ms 30284 KB Output is correct
94 Correct 373 ms 25044 KB Output is correct
95 Correct 579 ms 30312 KB Output is correct
96 Correct 675 ms 29900 KB Output is correct
97 Correct 467 ms 25688 KB Output is correct
98 Correct 467 ms 26324 KB Output is correct
99 Correct 630 ms 30036 KB Output is correct
100 Correct 648 ms 30540 KB Output is correct
101 Correct 643 ms 25960 KB Output is correct
102 Correct 617 ms 30524 KB Output is correct
103 Correct 489 ms 26328 KB Output is correct
104 Correct 712 ms 30692 KB Output is correct
105 Correct 293 ms 25932 KB Output is correct
106 Correct 484 ms 28696 KB Output is correct
107 Correct 411 ms 28604 KB Output is correct
108 Correct 394 ms 28496 KB Output is correct
109 Correct 386 ms 28500 KB Output is correct
110 Correct 379 ms 28372 KB Output is correct
111 Correct 382 ms 28364 KB Output is correct
112 Correct 384 ms 28364 KB Output is correct
113 Correct 381 ms 28236 KB Output is correct
114 Correct 398 ms 28376 KB Output is correct
115 Correct 394 ms 28236 KB Output is correct
116 Correct 389 ms 29396 KB Output is correct