#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;
void push(lli pos) {
if (stree[pos].hizq == 0) {
lli a = stree.size();
stree.push_back(trash);
stree.push_back(trash);
stree[pos].hizq = a;
stree[pos].hder = a+1;
}
stree[ stree[pos].hizq ].MIN = stree[pos].MIN;
stree[ stree[pos].hder ].MIN = stree[pos].MIN;
}
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)/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)/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;
circulo[i].x += largo;
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,0,largo*2,l,r);
//debugsl(l);
//debug(r);
if (a == 0) { //meto mi rango
res[act.id] = act.id;
update(0,0,largo*2,l,r,act.id);
}
else res[act.id] = a;
}
rep(i,1,n) cout << res[i] << ' ';
return 0;
}
Compilation message
circle_selection.cpp: In function 'int main()':
circle_selection.cpp:113:32: warning: integer overflow in expression of type 'int' results in '-294967296' [-Woverflow]
113 | lli a = query(0,0,largo*2,l,r);
| ^
circle_selection.cpp:120:29: warning: integer overflow in expression of type 'int' results in '-294967296' [-Woverflow]
120 | update(0,0,largo*2,l,r,act.id);
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
109 ms |
19104 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
97 ms |
19048 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |