#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define endl '\n'
#define INF 1e9+7
#define all(x) x.begin(),x.end()
using namespace std;
using namespace __gnu_pbds;
using ll=long long;
using pii=pair<int,int>;
using ppi=pair<int,pii>;
using oset=tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>;
template<typename T>
void _print(vector<T> x) {cerr<<"{"; for(auto e:x) cerr<<e<<","; cerr<<"}";}
void _print(pii x) {cerr<<"{"<<x.first<<","<<x.second<<"}";}
template<typename T>
void _print(T x) {cerr<<x;}
void dbg() {cerr<<endl;}
template<typename Head,typename... Tail>
void dbg(Head H,Tail... T) {
_print(H);
if(sizeof...(T)) cerr<<",";
else cerr<<"\"]";
dbg(T...);
}
#define debug(...) cerr<<"["<<#__VA_ARGS__<<"]:[\"",dbg(__VA_ARGS__)
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
struct dt {
ll l,r;
int idx;
bool intersect(const dt &rr) {
if(rr.l>=l and rr.l<=r) return true;
if(rr.r>=l and rr.r<=r) return true;
return false;
}
};
struct cmpL {
bool operator()(const dt &l,const dt &r) {
if(l.l==r.l) return l.r>r.r;
return l.l<r.l;
}
};
struct cmpR {
bool operator()(const dt &l,const dt &r) {
return l.r<r.r;
}
};
int main () {
ios::sync_with_stdio(false); cin.tie(0);
int n; cin>>n;
vector<dt> a(n);
set<dt,cmpL> sL;
set<dt,cmpR> sR;
for(int i=0;i<n;i++) {
int x,y,r; cin>>x>>y>>r;
a[i]={x-r,x+r,i};
sL.insert(a[i]);
sR.insert(a[i]);
}
sort(all(a),[&](const dt &l,const dt &r) {
if((l.r-l.l)==(r.r-r.l)) return l.l<r.l;
return (l.r-l.l)>(r.r-r.l);
});
vector<int> ans(n,-1);
for(int i=0;i<n;i++) {
int u=a[i].idx;
if(ans[u]!=-1) continue;
auto p=sL.lower_bound(a[i]);
vector<dt> to_del;
while(p!=sL.end()) {
int v=p->idx;
if(ans[v]!=-1) break;
if(!a[i].intersect(*p)) break;
to_del.push_back(*p);
// sL.erase(p); sR.erase(p);
ans[v]=u; p++;
}
for(auto e:to_del) sL.erase(e),sR.erase(e);
vector<dt> to_del2;
auto p2=sR.upper_bound(a[i]);
if(p2!=sR.begin()) --p2;
while(p2!=sR.begin()) {
int v=p2->idx;
if(ans[v]!=-1) break;
if(!a[i].intersect(*p2)) break;
to_del2.push_back(*p2);
// sL.erase(p2); sR.erase(p2);
ans[v]=u; p2--;
}
for(auto e:to_del2) sL.erase(e),sR.erase(e);
}
for(int i=0;i<n;i++) cout<<ans[i]+1<<" ";
cout<<endl;
}
# |
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 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1012 ms |
65264 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
534 ms |
55896 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 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
4 |
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 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |