// And you curse yourself for things you never done
#include<bits/stdc++.h>
#define F first
#define S second
#define PB push_back
#define sz(s) int((s).size())
#define bit(n,k) (((n)>>(k))&1)
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int maxn = 3e5 + 10, mod = 1e9 + 7, inf = 1e9 + 10;
const ll INF = 1e18;
pair<pii, int> p[maxn];
int arr[maxn], ans[maxn];
pii operator - (pii a, pii b){
return {a.F - b.F, a.S - b.S};
}
pii operator + (pii a, pii b){
return {a.F + b.F, a.S + b.S};
}
ll operator ^ (pii a, pii b){
return 1ll * a.F * b.F + 1ll * a.S * b.S;
}
bool ok(int i, int j){
return 1ll * (p[j].S + p[i].S) * (p[j].S + p[i].S) >= ((p[i].F - p[j].F) ^ (p[i].F - p[j].F));
}
const int FX = 40; ////////
vector<int> vx, vy;
vector<int> val, fs;
vector<int> stock;
void push(int &lst, int x){
fs.PB(lst);
lst = sz(val);
val.PB(x);
}
struct node{
set<pair<pii, int> > st;
void add(int f, int s, int x){
st.insert({{f, s}, x});
}
void ask(int pos){
auto it = st.lower_bound( (pair<pii, int>){ {pos + 1, -1}, -1} );
int bad = 2;
while(sz(stock) < FX && it != st.begin()){
--it;
if(pos <= (it->F.S))
stock.PB(it->S);
else{
if(--bad == 0)
break;
}
}
}
};
struct node2{
node2 *L = 0, *R = 0;
node* seg = 0;
void add(int f, int s, int f2, int s2, int x, int l = 0, int r = sz(vx)-1){
if(f <= vx[l] && vx[r] <= s){
if(!seg)
seg = new node();
seg->add(f2, s2, x);
return;
}
if(r-l == 1)
return;
int mid = (l+r) >> 1;
if(max(f, vx[l]) < min(s, vx[mid])){
if(!L)
L = new node2();
L->add(f, s, f2, s2, x, l, mid);
}
if(max(f, vx[mid]) < min(s, vx[r])){
if(!R)
R = new node2();
R->add(f, s, f2, s2, x, mid, r);
}
}
void ask(int pos, int pos2, int l = 0, int r = sz(vx)-1){
if(seg)
seg->ask(pos2);
if(r-l == 1)
return;
int mid = (l+r) >> 1;
if(pos < vx[mid] && L)
L->ask(pos, pos2, l, mid);
if(vx[mid] <= pos && R)
R->ask(pos, pos2, mid, r);
}
};
int main(){
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie();
node2* root = new node2();
int n;
cin >> n;
for(int i = 0; i < n; i++){
cin >> p[i].F.F >> p[i].F.S >> p[i].S;
vx.PB(p[i].F.F - p[i].S);
vx.PB(p[i].F.F + p[i].S + 1);
vy.PB(p[i].F.S - p[i].S);
vy.PB(p[i].F.S + p[i].S + 1);
arr[i] = i;
}
auto cmp = [](int i, int j){
return (p[i].S == p[j].S ? i > j : p[i].S < p[j].S);
};
sort(arr, arr + n, cmp);
sort(vx.begin(), vx.end());
vx.resize( unique(vx.begin(), vx.end()) - vx.begin() );
sort(vy.begin(), vy.end());
vy.resize( unique(vy.begin(), vy.end()) - vy.begin() );
for(int i = n-1; i >= 0; i--){
int I = arr[i];
stock.clear();
// cout << "IN " << I+1 << endl;
for(int msk = 0; msk < 4; msk++)
root->ask(p[I].F.F + (bit(msk, 0) ? 1 : -1) * p[I].S, p[I].F.S + (bit(msk, 1) ? 1 : -1) * p[I].S);
for(int id : stock){
// cout << "STOCK " << id+1 << endl;
if(ok(I, id)){
if(ans[I] == 0 || cmp(ans[I] - 1, id))
ans[I] = id + 1;
}
}
if(ans[I] == 0){
ans[I] = I + 1;
root->add(p[I].F.F - p[I].S, p[I].F.F + p[I].S + 1, p[I].F.S - p[I].S, p[I].F.S + p[I].S + 1, I);
}
}
for(int i = 0; i < n; i++){
cout << ans[i] << " ";
}
return cout << endl, 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
6 |
Correct |
0 ms |
384 KB |
Output is correct |
7 |
Correct |
0 ms |
384 KB |
Output is correct |
8 |
Correct |
0 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
0 ms |
384 KB |
Output is correct |
11 |
Correct |
0 ms |
384 KB |
Output is correct |
12 |
Correct |
0 ms |
384 KB |
Output is correct |
13 |
Correct |
1 ms |
384 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
15 |
Correct |
0 ms |
384 KB |
Output is correct |
16 |
Correct |
1 ms |
384 KB |
Output is correct |
17 |
Correct |
1 ms |
384 KB |
Output is correct |
18 |
Correct |
1 ms |
384 KB |
Output is correct |
19 |
Correct |
5 ms |
640 KB |
Output is correct |
20 |
Correct |
5 ms |
640 KB |
Output is correct |
21 |
Correct |
6 ms |
640 KB |
Output is correct |
22 |
Correct |
10 ms |
2304 KB |
Output is correct |
23 |
Correct |
17 ms |
3456 KB |
Output is correct |
24 |
Correct |
10 ms |
2048 KB |
Output is correct |
25 |
Correct |
9 ms |
1664 KB |
Output is correct |
26 |
Correct |
10 ms |
2048 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
356 ms |
13268 KB |
Output is correct |
2 |
Correct |
355 ms |
13260 KB |
Output is correct |
3 |
Correct |
393 ms |
13004 KB |
Output is correct |
4 |
Correct |
349 ms |
13224 KB |
Output is correct |
5 |
Correct |
592 ms |
17912 KB |
Output is correct |
6 |
Correct |
878 ms |
55884 KB |
Output is correct |
7 |
Correct |
1046 ms |
24260 KB |
Output is correct |
8 |
Correct |
828 ms |
33728 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
464 ms |
60644 KB |
Output is correct |
3 |
Correct |
1901 ms |
178460 KB |
Output is correct |
4 |
Correct |
1634 ms |
177776 KB |
Output is correct |
5 |
Correct |
2109 ms |
162368 KB |
Output is correct |
6 |
Correct |
775 ms |
65624 KB |
Output is correct |
7 |
Correct |
296 ms |
31200 KB |
Output is correct |
8 |
Correct |
34 ms |
4728 KB |
Output is correct |
9 |
Correct |
1970 ms |
180300 KB |
Output is correct |
10 |
Correct |
2928 ms |
144372 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1202 ms |
164156 KB |
Output is correct |
2 |
Correct |
751 ms |
78920 KB |
Output is correct |
3 |
Correct |
2065 ms |
33320 KB |
Output is correct |
4 |
Correct |
787 ms |
90444 KB |
Output is correct |
5 |
Correct |
838 ms |
84288 KB |
Output is correct |
6 |
Correct |
1328 ms |
17960 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
6 |
Correct |
0 ms |
384 KB |
Output is correct |
7 |
Correct |
0 ms |
384 KB |
Output is correct |
8 |
Correct |
0 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
0 ms |
384 KB |
Output is correct |
11 |
Correct |
0 ms |
384 KB |
Output is correct |
12 |
Correct |
0 ms |
384 KB |
Output is correct |
13 |
Correct |
1 ms |
384 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
15 |
Correct |
0 ms |
384 KB |
Output is correct |
16 |
Correct |
1 ms |
384 KB |
Output is correct |
17 |
Correct |
1 ms |
384 KB |
Output is correct |
18 |
Correct |
1 ms |
384 KB |
Output is correct |
19 |
Correct |
5 ms |
640 KB |
Output is correct |
20 |
Correct |
5 ms |
640 KB |
Output is correct |
21 |
Correct |
6 ms |
640 KB |
Output is correct |
22 |
Correct |
10 ms |
2304 KB |
Output is correct |
23 |
Correct |
17 ms |
3456 KB |
Output is correct |
24 |
Correct |
10 ms |
2048 KB |
Output is correct |
25 |
Correct |
9 ms |
1664 KB |
Output is correct |
26 |
Correct |
10 ms |
2048 KB |
Output is correct |
27 |
Correct |
12 ms |
896 KB |
Output is correct |
28 |
Correct |
11 ms |
896 KB |
Output is correct |
29 |
Correct |
10 ms |
896 KB |
Output is correct |
30 |
Correct |
28 ms |
5752 KB |
Output is correct |
31 |
Correct |
22 ms |
4088 KB |
Output is correct |
32 |
Correct |
28 ms |
3960 KB |
Output is correct |
33 |
Correct |
125 ms |
4708 KB |
Output is correct |
34 |
Correct |
115 ms |
4704 KB |
Output is correct |
35 |
Correct |
126 ms |
4676 KB |
Output is correct |
36 |
Correct |
372 ms |
43104 KB |
Output is correct |
37 |
Correct |
315 ms |
44132 KB |
Output is correct |
38 |
Correct |
404 ms |
48928 KB |
Output is correct |
39 |
Correct |
282 ms |
8676 KB |
Output is correct |
40 |
Correct |
303 ms |
8672 KB |
Output is correct |
41 |
Correct |
282 ms |
8544 KB |
Output is correct |
42 |
Correct |
275 ms |
8544 KB |
Output is correct |
43 |
Correct |
239 ms |
26080 KB |
Output is correct |
44 |
Correct |
235 ms |
26212 KB |
Output is correct |
45 |
Correct |
252 ms |
26080 KB |
Output is correct |
46 |
Correct |
242 ms |
26080 KB |
Output is correct |
47 |
Correct |
246 ms |
26212 KB |
Output is correct |
48 |
Correct |
249 ms |
26084 KB |
Output is correct |
49 |
Correct |
237 ms |
26212 KB |
Output is correct |
50 |
Correct |
244 ms |
26212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
6 |
Correct |
0 ms |
384 KB |
Output is correct |
7 |
Correct |
0 ms |
384 KB |
Output is correct |
8 |
Correct |
0 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
0 ms |
384 KB |
Output is correct |
11 |
Correct |
0 ms |
384 KB |
Output is correct |
12 |
Correct |
0 ms |
384 KB |
Output is correct |
13 |
Correct |
1 ms |
384 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
15 |
Correct |
0 ms |
384 KB |
Output is correct |
16 |
Correct |
1 ms |
384 KB |
Output is correct |
17 |
Correct |
1 ms |
384 KB |
Output is correct |
18 |
Correct |
1 ms |
384 KB |
Output is correct |
19 |
Correct |
5 ms |
640 KB |
Output is correct |
20 |
Correct |
5 ms |
640 KB |
Output is correct |
21 |
Correct |
6 ms |
640 KB |
Output is correct |
22 |
Correct |
10 ms |
2304 KB |
Output is correct |
23 |
Correct |
17 ms |
3456 KB |
Output is correct |
24 |
Correct |
10 ms |
2048 KB |
Output is correct |
25 |
Correct |
9 ms |
1664 KB |
Output is correct |
26 |
Correct |
10 ms |
2048 KB |
Output is correct |
27 |
Correct |
356 ms |
13268 KB |
Output is correct |
28 |
Correct |
355 ms |
13260 KB |
Output is correct |
29 |
Correct |
393 ms |
13004 KB |
Output is correct |
30 |
Correct |
349 ms |
13224 KB |
Output is correct |
31 |
Correct |
592 ms |
17912 KB |
Output is correct |
32 |
Correct |
878 ms |
55884 KB |
Output is correct |
33 |
Correct |
1046 ms |
24260 KB |
Output is correct |
34 |
Correct |
828 ms |
33728 KB |
Output is correct |
35 |
Correct |
0 ms |
384 KB |
Output is correct |
36 |
Correct |
464 ms |
60644 KB |
Output is correct |
37 |
Correct |
1901 ms |
178460 KB |
Output is correct |
38 |
Correct |
1634 ms |
177776 KB |
Output is correct |
39 |
Correct |
2109 ms |
162368 KB |
Output is correct |
40 |
Correct |
775 ms |
65624 KB |
Output is correct |
41 |
Correct |
296 ms |
31200 KB |
Output is correct |
42 |
Correct |
34 ms |
4728 KB |
Output is correct |
43 |
Correct |
1970 ms |
180300 KB |
Output is correct |
44 |
Correct |
2928 ms |
144372 KB |
Output is correct |
45 |
Correct |
1202 ms |
164156 KB |
Output is correct |
46 |
Correct |
751 ms |
78920 KB |
Output is correct |
47 |
Correct |
2065 ms |
33320 KB |
Output is correct |
48 |
Correct |
787 ms |
90444 KB |
Output is correct |
49 |
Correct |
838 ms |
84288 KB |
Output is correct |
50 |
Correct |
1328 ms |
17960 KB |
Output is correct |
51 |
Correct |
12 ms |
896 KB |
Output is correct |
52 |
Correct |
11 ms |
896 KB |
Output is correct |
53 |
Correct |
10 ms |
896 KB |
Output is correct |
54 |
Correct |
28 ms |
5752 KB |
Output is correct |
55 |
Correct |
22 ms |
4088 KB |
Output is correct |
56 |
Correct |
28 ms |
3960 KB |
Output is correct |
57 |
Correct |
125 ms |
4708 KB |
Output is correct |
58 |
Correct |
115 ms |
4704 KB |
Output is correct |
59 |
Correct |
126 ms |
4676 KB |
Output is correct |
60 |
Correct |
372 ms |
43104 KB |
Output is correct |
61 |
Correct |
315 ms |
44132 KB |
Output is correct |
62 |
Correct |
404 ms |
48928 KB |
Output is correct |
63 |
Correct |
282 ms |
8676 KB |
Output is correct |
64 |
Correct |
303 ms |
8672 KB |
Output is correct |
65 |
Correct |
282 ms |
8544 KB |
Output is correct |
66 |
Correct |
275 ms |
8544 KB |
Output is correct |
67 |
Correct |
239 ms |
26080 KB |
Output is correct |
68 |
Correct |
235 ms |
26212 KB |
Output is correct |
69 |
Correct |
252 ms |
26080 KB |
Output is correct |
70 |
Correct |
242 ms |
26080 KB |
Output is correct |
71 |
Correct |
246 ms |
26212 KB |
Output is correct |
72 |
Correct |
249 ms |
26084 KB |
Output is correct |
73 |
Correct |
237 ms |
26212 KB |
Output is correct |
74 |
Correct |
244 ms |
26212 KB |
Output is correct |
75 |
Correct |
382 ms |
13000 KB |
Output is correct |
76 |
Correct |
383 ms |
13260 KB |
Output is correct |
77 |
Correct |
363 ms |
13256 KB |
Output is correct |
78 |
Correct |
378 ms |
13012 KB |
Output is correct |
79 |
Correct |
619 ms |
15048 KB |
Output is correct |
80 |
Correct |
376 ms |
13000 KB |
Output is correct |
81 |
Correct |
1706 ms |
170544 KB |
Output is correct |
82 |
Correct |
1442 ms |
155172 KB |
Output is correct |
83 |
Correct |
1413 ms |
155920 KB |
Output is correct |
84 |
Correct |
1803 ms |
193356 KB |
Output is correct |
85 |
Correct |
1459 ms |
165708 KB |
Output is correct |
86 |
Correct |
1219 ms |
151872 KB |
Output is correct |
87 |
Execution timed out |
3092 ms |
228512 KB |
Time limit exceeded |
88 |
Halted |
0 ms |
0 KB |
- |