#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define debug(a) cout << #a << " = " << a << endl
#define debugsl(a) cout << #a << " = " << a << ", "
#define rep(i,a,b) for(int i = (a); i <= (b); i++)
#define repa(i,a,b) for(int i = (a); i >= (b); i--)
#define pll pair<lli,lli>
#define INF (1ll<<60)
#define MAX 300000
#define largo 2000000000
//para el vector de orden
#define id second
struct xx {
lli x;
lli y;
lli r;
};
struct yy {
lli MIN;
lli hizq;
lli hder;
};
lli n,cont;
lli res[MAX+2],new_order[MAX+2];
xx circulo[MAX+2];
vector<pll> orden;
vector<yy> stree;
yy trash;
bool push(lli pos) {
if (stree[pos].hizq != 0) return true;
lli a = stree.size();
stree.push_back(trash);
stree.push_back(trash);
stree[pos].hizq = a;
stree[pos].hder = a+1;
stree[a].MIN = stree[pos].MIN;
stree[a+1].MIN = stree[pos].MIN;
return false;
}
lli query(lli pos, lli ini, lli fin, lli l, lli r) {
if (ini > r || fin < l) return 0;
if (l <= ini && fin <= r) return stree[pos].MIN;
//debugsl(ini);
//debugsl(fin);
//debugsl(l);
//debug(r);
lli mitad = ini+fin; // problema???
if (mitad < 0) mitad--;
mitad/=2;
push(pos);
lli a = query(stree[pos].hizq, ini,mitad,l,r);
lli b = query(stree[pos].hder, mitad+1,fin,l,r);
if (new_order[a] < new_order[b]) return a;
else return b;
}
void update(lli pos, lli ini, lli fin, lli l, lli r, lli val) {
if (ini > r || fin < l) return;
if (l <= ini && fin <= r) {
stree[pos].MIN = val;
return;
}
lli mitad = ini+fin;
if (mitad < 0) mitad--;
mitad/=2;
push(pos);
update(stree[pos].hizq, ini,mitad,l,r,val);
update(stree[pos].hder, mitad+1,fin,l,r,val);
lli a = stree[ stree[pos].hizq ].MIN;
lli b = stree[ stree[pos].hder ].MIN;
if (new_order[a] < new_order[b]) stree[pos].MIN = a;
else stree[pos].MIN = b;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n;
rep(i,1,n) {
cin >> circulo[i].x >> circulo[i].y >> circulo[i].r;
orden.push_back({-circulo[i].r, i});
}
sort(orden.begin(), orden.end());
stree.push_back(trash);
cont = 1;
new_order[0] = INF;
for (auto act : orden) {
new_order[act.id] = cont++;
//debug(act.id);
lli l = circulo[act.id].x - circulo[act.id].r;
lli r = circulo[act.id].x + circulo[act.id].r;
lli a = query(0,-largo,largo,l,r);
//debugsl(l);
//debug(r);
if (a == 0) { //meto mi rango
res[act.id] = act.id;
update(0,-largo,largo,l,r,act.id);
}
else res[act.id] = a;
}
rep(i,1,n) cout << res[i] << ' ';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
292 KB |
Output is correct |
3 |
Incorrect |
0 ms |
340 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
910 ms |
416876 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
724 ms |
415896 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
292 KB |
Output is correct |
3 |
Incorrect |
0 ms |
340 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
292 KB |
Output is correct |
3 |
Incorrect |
0 ms |
340 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |