Submission #407845

# Submission time Handle Problem Language Result Execution time Memory
407845 2021-05-19T04:49:27 Z amunduzbaev Circle selection (APIO18_circle_selection) C++14
19 / 100
1404 ms 64284 KB
#include "bits/stdc++.h"
using namespace std;

#define pb push_back
#define int long long
#define pii pair<int, int>
#define ff first
#define ss second
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define lb lower_bound
#define ub upper_bound

const int N = 3e5+5;
const int M = 5e3+5;
const int mod = 1e9+7;

int n, m, k, a[N];
int rr[N];
pii p[N];

bool cmp(pii a, pii b){
	if(a.ff != b.ff) return a.ff > b.ff;
	return a.ss < b.ss; 
} int sq(int x) { return x * x; } 
int dis(int i, int j){ pii a = p[i], b = p[j];
	return sqrt(sq(a.ff - b.ff) + sq(a.ss - b.ss)); 
} 

/*

11
9 0 2
13 0 1
11 0 2
3 0 2
3 0 1
12 0 1
9 0 5
2 0 2
5 0 1
14 0 2
14 0 1

*/

signed main(){
	cin>>n;
	if(n <= 5000) {
		vector<pii> tt;
		for(int i=0;i<n;i++) cin>>p[i].ff>>p[i].ss>>a[i], tt.pb({a[i], i});
		sort(all(tt), cmp);
		for(auto x : tt){
			if(rr[x.ss]) continue;
			for(int i=0;i<n;i++){
				if(rr[i]) continue;
				if(dis(x.ss, i) <= a[x.ss] + a[i]) rr[i] = x.ss+1;
			}
		} 
	} else {
		vector<pii> tt;
		for(int i=0;i<n;i++) cin>>p[i].ff>>p[i].ss>>a[i], tt.pb({a[i], i});
		sort(all(tt), cmp);
		
		memset(rr, -1, sizeof rr);
		set<pii> ss;
		for(int i=0;i<n;i++) ss.insert({p[i].ff - a[i], i}), ss.insert({p[i].ff + a[i], i});
		
		for(auto x : tt){
			if(~rr[x.ss]) continue;
			int l = p[x.ss].ff - x.ff, r = p[x.ss].ff + x.ff;
			auto lx = ss.lb(make_pair(l, 0));
			vector<pii> er;
			while(lx != ss.end() && (*lx).ff <= r){
				int in = (*lx).ss;
				if(rr[in] == -1) rr[in] = x.ss + 1;
				er.pb(*lx), lx++;
			}
			for(auto x : er) ss.erase(x);
		}
	} 
	
	for(int i=0;i<n;i++) cout<<rr[i]<<" ";
	cout<<"\n";
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 2 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 2 ms 256 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 2 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 256 KB Output is correct
16 Correct 4 ms 332 KB Output is correct
17 Correct 4 ms 352 KB Output is correct
18 Correct 2 ms 332 KB Output is correct
19 Correct 9 ms 588 KB Output is correct
20 Correct 9 ms 636 KB Output is correct
21 Correct 9 ms 588 KB Output is correct
22 Correct 108 ms 616 KB Output is correct
23 Correct 109 ms 680 KB Output is correct
24 Correct 110 ms 588 KB Output is correct
25 Correct 122 ms 680 KB Output is correct
26 Correct 115 ms 588 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1270 ms 64192 KB Output is correct
2 Correct 1404 ms 64248 KB Output is correct
3 Correct 1255 ms 64284 KB Output is correct
4 Correct 1348 ms 64204 KB Output is correct
5 Correct 1068 ms 51880 KB Output is correct
6 Correct 1216 ms 51968 KB Output is correct
7 Correct 1133 ms 51952 KB Output is correct
8 Correct 1106 ms 51892 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Incorrect 419 ms 18972 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1257 ms 51876 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 2 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 2 ms 256 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 2 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 256 KB Output is correct
16 Correct 4 ms 332 KB Output is correct
17 Correct 4 ms 352 KB Output is correct
18 Correct 2 ms 332 KB Output is correct
19 Correct 9 ms 588 KB Output is correct
20 Correct 9 ms 636 KB Output is correct
21 Correct 9 ms 588 KB Output is correct
22 Correct 108 ms 616 KB Output is correct
23 Correct 109 ms 680 KB Output is correct
24 Correct 110 ms 588 KB Output is correct
25 Correct 122 ms 680 KB Output is correct
26 Correct 115 ms 588 KB Output is correct
27 Incorrect 29 ms 4992 KB Output isn't correct
28 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 2 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 2 ms 256 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 2 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 256 KB Output is correct
16 Correct 4 ms 332 KB Output is correct
17 Correct 4 ms 352 KB Output is correct
18 Correct 2 ms 332 KB Output is correct
19 Correct 9 ms 588 KB Output is correct
20 Correct 9 ms 636 KB Output is correct
21 Correct 9 ms 588 KB Output is correct
22 Correct 108 ms 616 KB Output is correct
23 Correct 109 ms 680 KB Output is correct
24 Correct 110 ms 588 KB Output is correct
25 Correct 122 ms 680 KB Output is correct
26 Correct 115 ms 588 KB Output is correct
27 Correct 1270 ms 64192 KB Output is correct
28 Correct 1404 ms 64248 KB Output is correct
29 Correct 1255 ms 64284 KB Output is correct
30 Correct 1348 ms 64204 KB Output is correct
31 Correct 1068 ms 51880 KB Output is correct
32 Correct 1216 ms 51968 KB Output is correct
33 Correct 1133 ms 51952 KB Output is correct
34 Correct 1106 ms 51892 KB Output is correct
35 Correct 1 ms 204 KB Output is correct
36 Incorrect 419 ms 18972 KB Output isn't correct
37 Halted 0 ms 0 KB -