#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));
}
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);
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.find(make_pair(l, x.ss));
vector<pii> er;
while(lx != ss.end() && (*lx).ff <= r)
er.pb(*lx), rr[(*lx).ss] = x.ss + 1, 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 |
2 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
300 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
256 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 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 |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
3 ms |
384 KB |
Output is correct |
17 |
Correct |
2 ms |
332 KB |
Output is correct |
18 |
Correct |
3 ms |
332 KB |
Output is correct |
19 |
Correct |
10 ms |
784 KB |
Output is correct |
20 |
Correct |
9 ms |
764 KB |
Output is correct |
21 |
Correct |
9 ms |
796 KB |
Output is correct |
22 |
Correct |
108 ms |
792 KB |
Output is correct |
23 |
Correct |
105 ms |
716 KB |
Output is correct |
24 |
Correct |
121 ms |
724 KB |
Output is correct |
25 |
Correct |
128 ms |
744 KB |
Output is correct |
26 |
Correct |
107 ms |
772 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1218 ms |
65288 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Incorrect |
311 ms |
18260 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1191 ms |
52904 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
300 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
256 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 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 |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
3 ms |
384 KB |
Output is correct |
17 |
Correct |
2 ms |
332 KB |
Output is correct |
18 |
Correct |
3 ms |
332 KB |
Output is correct |
19 |
Correct |
10 ms |
784 KB |
Output is correct |
20 |
Correct |
9 ms |
764 KB |
Output is correct |
21 |
Correct |
9 ms |
796 KB |
Output is correct |
22 |
Correct |
108 ms |
792 KB |
Output is correct |
23 |
Correct |
105 ms |
716 KB |
Output is correct |
24 |
Correct |
121 ms |
724 KB |
Output is correct |
25 |
Correct |
128 ms |
744 KB |
Output is correct |
26 |
Correct |
107 ms |
772 KB |
Output is correct |
27 |
Incorrect |
25 ms |
3140 KB |
Output isn't correct |
28 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
300 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
256 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 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 |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
3 ms |
384 KB |
Output is correct |
17 |
Correct |
2 ms |
332 KB |
Output is correct |
18 |
Correct |
3 ms |
332 KB |
Output is correct |
19 |
Correct |
10 ms |
784 KB |
Output is correct |
20 |
Correct |
9 ms |
764 KB |
Output is correct |
21 |
Correct |
9 ms |
796 KB |
Output is correct |
22 |
Correct |
108 ms |
792 KB |
Output is correct |
23 |
Correct |
105 ms |
716 KB |
Output is correct |
24 |
Correct |
121 ms |
724 KB |
Output is correct |
25 |
Correct |
128 ms |
744 KB |
Output is correct |
26 |
Correct |
107 ms |
772 KB |
Output is correct |
27 |
Incorrect |
1218 ms |
65288 KB |
Output isn't correct |
28 |
Halted |
0 ms |
0 KB |
- |