#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;
// dt(ll L,ll R,int IDX) {
// l=L,r=R,idx=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) {
if(l.r!=r.r) return l.r<r.r;
else return l.idx<r.idx;
}
return l.l<r.l;
}
};
struct cmpR {
bool operator()(const dt &l,const dt &r) {
if(l.r==r.r) {
if(l.l!=r.l) return l.l<r.l;
return l.idx<r.idx;
}
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;
ans[u]=u; sL.erase(a[i]); sR.erase(a[i]);
auto p=sL.lower_bound({a[i].l,-1,-1});
vector<dt> to_del;
// debug(i,a[i].idx);
while(p!=sL.end()) {
// cout<<"#"<<p->l<<" "<<p->r<<" ("<<p->idx<<")"<<endl;
int v=p->idx;
if(ans[v]!=-1) break;;
if(!a[i].intersect(*p)) break;
to_del.push_back(*p);
ans[v]=u; p++;
}
for(auto e:to_del) {
// cout<<"@"<<e.l<<" "<<e.r<<" ("<<e.idx<<")"<<endl;
// debug(sR.size(),"BF");
sL.erase(e); sR.erase(e);
// debug(sR.size(),"AF");
}
// for(auto e:sR) {
// cout<<"R"<<e.l<<" "<<e.r<<" "<<e.idx<<endl;
// }
if(sR.empty()) continue;
vector<dt> to_del2;
auto p2=sR.upper_bound({-1,a[i].r,-1});
if(p2!=sR.begin() &&(p2==sR.end() ||(!a[i].intersect(*p2)))) p2--;
while(p2!=sR.begin()) {
// cout<<"#"<<p2->l<<" "<<p2->r<<" ("<<p2->idx<<")"<<endl;
int v=p2->idx;
if(ans[v]!=-1) break;;
if(!a[i].intersect(*p2)) break;
to_del2.push_back(*p2);
ans[v]=u; p2--;
}
if(!sR.empty()) {
int v=p2->idx;
if(ans[v]==-1 and a[i].intersect(*p2)) {
ans[v]=u; to_del2.push_back(*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 |
Correct |
1084 ms |
58464 KB |
Output is correct |
2 |
Correct |
1050 ms |
60736 KB |
Output is correct |
3 |
Correct |
1074 ms |
61740 KB |
Output is correct |
4 |
Correct |
1060 ms |
63060 KB |
Output is correct |
5 |
Incorrect |
780 ms |
52676 KB |
Output isn't correct |
6 |
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 |
563 ms |
48152 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 |
- |