답안 #254361

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
254361 2020-07-29T21:50:09 Z shayan_p 원 고르기 (APIO18_circle_selection) C++14
100 / 100
1690 ms 661820 KB
// 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;
typedef pair<ll, ll> pll;
typedef unsigned int ui;

const int maxn = 3e5 + 10, mod = 1e9 + 7, inf = 1e9 + 10;
 
pair<pll, ll> p[maxn];
int arr[maxn], ans[maxn];
 
pll operator - (pll a, pll b){
    return {a.F - b.F, a.S - b.S};
}
pll operator + (pll a, pll b){
    return {a.F + b.F, a.S + b.S};
}
ll operator ^ (pll a, pll 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 Log = 31;

struct node{
    node *nxt[2][2];
    vector<int> vec;
    node(){
	nxt[0][0] = nxt[0][1] = nxt[1][0] = nxt[1][1] = 0;
    }
};node* rt;

void add(int msk1, int msk2, int id){
    node* nw = rt;
    for(int i = Log-1; i >= 0; i--){
	nw->vec.PB(id);
	if(nw->nxt[bit(msk1, i)][bit(msk2, i)] == 0)
	    nw->nxt[bit(msk1, i)][bit(msk2, i)] = new node();
	nw = nw->nxt[bit(msk1, i)][bit(msk2, i)];
    }
    nw->vec.PB(id);
}

vector<node*> fnds;

void fnd(node* nw, ui l1, ui r1, ui l2, ui r2, ui L1 = 0, ui R1 = 1<<31, ui L2 = 0, ui R2 = 1<<31){
    if(r1 <= L1 || R1 <= l1 || r2 <= L2 || R2 <= l2)
	return;
    if(l1 <= L1 && R1 <= r1 && l2 <= L2 && R2 <= r2){
	fnds.PB(nw);
	return;
    }
    ui mid1 = (L1 + R1) >> 1;
    ui mid2 = (L2 + R2) >> 1;
    if(nw->nxt[0][0])
	fnd(nw->nxt[0][0], l1, r1, l2, r2, L1, mid1, L2, mid2);
    if(nw->nxt[0][1])
	fnd(nw->nxt[0][1], l1, r1, l2, r2, L1, mid1, mid2, R2);
    if(nw->nxt[1][0])
	fnd(nw->nxt[1][0], l1, r1, l2, r2, mid1, R1, L2, mid2);
    if(nw->nxt[1][1])
	fnd(nw->nxt[1][1], l1, r1, l2, r2, mid1, R1, mid2, R2);    	
}

int cnt[maxn];

int main(){
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie();

    rt = new node();
	
    memset(ans, -1, sizeof ans);

    int n;    
    cin >> n;

    for(int i = 0; i < n; i++){
	cin >> p[i].F.F >> p[i].F.S >> p[i].S;
	p[i].F.F+= inf, p[i].F.S+= inf;
    }
    auto cmp = [](int i, int j){
		   return (p[i].S == p[j].S ? i > j : p[i].S < p[j].S);
	       };
    iota(arr, arr + n, 0);
    sort(arr, arr + n, cmp);
    
    for(int i = 0; i < n; i++){
	add(p[i].F.F, p[i].F.S, i);
    }
    
    int len = 0;
    
    for(int I = n-1; I >= 0; I--){
	int i = arr[I];
	while(Log > len && (1<<(Log-len-1)) >= p[i].S)
	    len++;
	if(ans[i] == -1){
	    ans[i] = i;
	    ll x = (p[i].F.F >> (Log - len)) << (Log - len), y = (p[i].F.S >> (Log-len)) << (Log - len), df = 1<<(Log-len);
	    fnds.clear();
	    fnd(rt, max(ll(0), x - 2ll * df), min(1ll<<Log, x + 3ll * df), max(ll(0), y - 2ll * df), min(1ll<<Log, y + 3ll * df));
	    for(node* nw : fnds){
		vector<int> vec;
		for(int id : nw->vec){
		    if(ans[id] == -1 && ok(id, i))
			ans[id] = i;
		    if(ans[id] == -1)
			vec.PB(id);//, assert(++cnt[id] <= 10);
		}
		nw->vec = vec;
	    }
	}
    }
    for(int i = 0; i < n; i++){
	cout << ans[i] + 1 << " ";
    }
    return cout << endl, 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1536 KB Output is correct
2 Correct 1 ms 1536 KB Output is correct
3 Correct 1 ms 1536 KB Output is correct
4 Correct 1 ms 1536 KB Output is correct
5 Correct 1 ms 1536 KB Output is correct
6 Correct 2 ms 1792 KB Output is correct
7 Correct 1 ms 1792 KB Output is correct
8 Correct 1 ms 1792 KB Output is correct
9 Correct 1 ms 1792 KB Output is correct
10 Correct 1 ms 1792 KB Output is correct
11 Correct 1 ms 1792 KB Output is correct
12 Correct 1 ms 1792 KB Output is correct
13 Correct 1 ms 1792 KB Output is correct
14 Correct 1 ms 1792 KB Output is correct
15 Correct 2 ms 1792 KB Output is correct
16 Correct 4 ms 3968 KB Output is correct
17 Correct 4 ms 3712 KB Output is correct
18 Correct 4 ms 3840 KB Output is correct
19 Correct 18 ms 12288 KB Output is correct
20 Correct 13 ms 10112 KB Output is correct
21 Correct 19 ms 13056 KB Output is correct
22 Correct 19 ms 12288 KB Output is correct
23 Correct 20 ms 11520 KB Output is correct
24 Correct 20 ms 12672 KB Output is correct
25 Correct 22 ms 13312 KB Output is correct
26 Correct 22 ms 12928 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 870 ms 379528 KB Output is correct
2 Correct 887 ms 390608 KB Output is correct
3 Correct 935 ms 372384 KB Output is correct
4 Correct 1004 ms 405848 KB Output is correct
5 Correct 665 ms 97328 KB Output is correct
6 Correct 1084 ms 239608 KB Output is correct
7 Correct 799 ms 164320 KB Output is correct
8 Correct 797 ms 189004 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1536 KB Output is correct
2 Correct 462 ms 228212 KB Output is correct
3 Correct 1507 ms 661820 KB Output is correct
4 Correct 1457 ms 661736 KB Output is correct
5 Correct 1441 ms 593740 KB Output is correct
6 Correct 646 ms 320492 KB Output is correct
7 Correct 370 ms 168688 KB Output is correct
8 Correct 59 ms 35576 KB Output is correct
9 Correct 1409 ms 602424 KB Output is correct
10 Correct 1301 ms 620132 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1329 ms 608848 KB Output is correct
2 Correct 1289 ms 583048 KB Output is correct
3 Correct 1074 ms 609360 KB Output is correct
4 Correct 1342 ms 626660 KB Output is correct
5 Correct 1335 ms 606152 KB Output is correct
6 Correct 1020 ms 598600 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1536 KB Output is correct
2 Correct 1 ms 1536 KB Output is correct
3 Correct 1 ms 1536 KB Output is correct
4 Correct 1 ms 1536 KB Output is correct
5 Correct 1 ms 1536 KB Output is correct
6 Correct 2 ms 1792 KB Output is correct
7 Correct 1 ms 1792 KB Output is correct
8 Correct 1 ms 1792 KB Output is correct
9 Correct 1 ms 1792 KB Output is correct
10 Correct 1 ms 1792 KB Output is correct
11 Correct 1 ms 1792 KB Output is correct
12 Correct 1 ms 1792 KB Output is correct
13 Correct 1 ms 1792 KB Output is correct
14 Correct 1 ms 1792 KB Output is correct
15 Correct 2 ms 1792 KB Output is correct
16 Correct 4 ms 3968 KB Output is correct
17 Correct 4 ms 3712 KB Output is correct
18 Correct 4 ms 3840 KB Output is correct
19 Correct 18 ms 12288 KB Output is correct
20 Correct 13 ms 10112 KB Output is correct
21 Correct 19 ms 13056 KB Output is correct
22 Correct 19 ms 12288 KB Output is correct
23 Correct 20 ms 11520 KB Output is correct
24 Correct 20 ms 12672 KB Output is correct
25 Correct 22 ms 13312 KB Output is correct
26 Correct 22 ms 12928 KB Output is correct
27 Correct 34 ms 23296 KB Output is correct
28 Correct 34 ms 22264 KB Output is correct
29 Correct 31 ms 23288 KB Output is correct
30 Correct 41 ms 22396 KB Output is correct
31 Correct 38 ms 22400 KB Output is correct
32 Correct 43 ms 23160 KB Output is correct
33 Correct 349 ms 200792 KB Output is correct
34 Correct 333 ms 209764 KB Output is correct
35 Correct 377 ms 205408 KB Output is correct
36 Correct 495 ms 203876 KB Output is correct
37 Correct 512 ms 211944 KB Output is correct
38 Correct 504 ms 206440 KB Output is correct
39 Correct 270 ms 33980 KB Output is correct
40 Correct 300 ms 35152 KB Output is correct
41 Correct 262 ms 35100 KB Output is correct
42 Correct 269 ms 99008 KB Output is correct
43 Correct 400 ms 161504 KB Output is correct
44 Correct 425 ms 161644 KB Output is correct
45 Correct 390 ms 161516 KB Output is correct
46 Correct 395 ms 161644 KB Output is correct
47 Correct 414 ms 161644 KB Output is correct
48 Correct 407 ms 161632 KB Output is correct
49 Correct 403 ms 161644 KB Output is correct
50 Correct 429 ms 161644 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1536 KB Output is correct
2 Correct 1 ms 1536 KB Output is correct
3 Correct 1 ms 1536 KB Output is correct
4 Correct 1 ms 1536 KB Output is correct
5 Correct 1 ms 1536 KB Output is correct
6 Correct 2 ms 1792 KB Output is correct
7 Correct 1 ms 1792 KB Output is correct
8 Correct 1 ms 1792 KB Output is correct
9 Correct 1 ms 1792 KB Output is correct
10 Correct 1 ms 1792 KB Output is correct
11 Correct 1 ms 1792 KB Output is correct
12 Correct 1 ms 1792 KB Output is correct
13 Correct 1 ms 1792 KB Output is correct
14 Correct 1 ms 1792 KB Output is correct
15 Correct 2 ms 1792 KB Output is correct
16 Correct 4 ms 3968 KB Output is correct
17 Correct 4 ms 3712 KB Output is correct
18 Correct 4 ms 3840 KB Output is correct
19 Correct 18 ms 12288 KB Output is correct
20 Correct 13 ms 10112 KB Output is correct
21 Correct 19 ms 13056 KB Output is correct
22 Correct 19 ms 12288 KB Output is correct
23 Correct 20 ms 11520 KB Output is correct
24 Correct 20 ms 12672 KB Output is correct
25 Correct 22 ms 13312 KB Output is correct
26 Correct 22 ms 12928 KB Output is correct
27 Correct 870 ms 379528 KB Output is correct
28 Correct 887 ms 390608 KB Output is correct
29 Correct 935 ms 372384 KB Output is correct
30 Correct 1004 ms 405848 KB Output is correct
31 Correct 665 ms 97328 KB Output is correct
32 Correct 1084 ms 239608 KB Output is correct
33 Correct 799 ms 164320 KB Output is correct
34 Correct 797 ms 189004 KB Output is correct
35 Correct 2 ms 1536 KB Output is correct
36 Correct 462 ms 228212 KB Output is correct
37 Correct 1507 ms 661820 KB Output is correct
38 Correct 1457 ms 661736 KB Output is correct
39 Correct 1441 ms 593740 KB Output is correct
40 Correct 646 ms 320492 KB Output is correct
41 Correct 370 ms 168688 KB Output is correct
42 Correct 59 ms 35576 KB Output is correct
43 Correct 1409 ms 602424 KB Output is correct
44 Correct 1301 ms 620132 KB Output is correct
45 Correct 1329 ms 608848 KB Output is correct
46 Correct 1289 ms 583048 KB Output is correct
47 Correct 1074 ms 609360 KB Output is correct
48 Correct 1342 ms 626660 KB Output is correct
49 Correct 1335 ms 606152 KB Output is correct
50 Correct 1020 ms 598600 KB Output is correct
51 Correct 34 ms 23296 KB Output is correct
52 Correct 34 ms 22264 KB Output is correct
53 Correct 31 ms 23288 KB Output is correct
54 Correct 41 ms 22396 KB Output is correct
55 Correct 38 ms 22400 KB Output is correct
56 Correct 43 ms 23160 KB Output is correct
57 Correct 349 ms 200792 KB Output is correct
58 Correct 333 ms 209764 KB Output is correct
59 Correct 377 ms 205408 KB Output is correct
60 Correct 495 ms 203876 KB Output is correct
61 Correct 512 ms 211944 KB Output is correct
62 Correct 504 ms 206440 KB Output is correct
63 Correct 270 ms 33980 KB Output is correct
64 Correct 300 ms 35152 KB Output is correct
65 Correct 262 ms 35100 KB Output is correct
66 Correct 269 ms 99008 KB Output is correct
67 Correct 400 ms 161504 KB Output is correct
68 Correct 425 ms 161644 KB Output is correct
69 Correct 390 ms 161516 KB Output is correct
70 Correct 395 ms 161644 KB Output is correct
71 Correct 414 ms 161644 KB Output is correct
72 Correct 407 ms 161632 KB Output is correct
73 Correct 403 ms 161644 KB Output is correct
74 Correct 429 ms 161644 KB Output is correct
75 Correct 1030 ms 629988 KB Output is correct
76 Correct 1032 ms 496052 KB Output is correct
77 Correct 980 ms 542664 KB Output is correct
78 Correct 1025 ms 620996 KB Output is correct
79 Correct 1104 ms 636132 KB Output is correct
80 Correct 1045 ms 608108 KB Output is correct
81 Correct 1690 ms 619732 KB Output is correct
82 Correct 1604 ms 622168 KB Output is correct
83 Correct 1452 ms 631176 KB Output is correct
84 Correct 1427 ms 588676 KB Output is correct
85 Correct 1467 ms 637796 KB Output is correct
86 Correct 1677 ms 633304 KB Output is correct
87 Correct 1438 ms 561476 KB Output is correct
88 Correct 941 ms 101680 KB Output is correct
89 Correct 958 ms 101600 KB Output is correct
90 Correct 1042 ms 101724 KB Output is correct
91 Correct 956 ms 101844 KB Output is correct
92 Correct 974 ms 101636 KB Output is correct
93 Correct 1278 ms 363980 KB Output is correct
94 Correct 1309 ms 397788 KB Output is correct
95 Correct 1262 ms 368308 KB Output is correct
96 Correct 1226 ms 339736 KB Output is correct
97 Correct 1295 ms 407500 KB Output is correct
98 Correct 1026 ms 261752 KB Output is correct
99 Correct 1325 ms 408380 KB Output is correct
100 Correct 1285 ms 415828 KB Output is correct
101 Correct 1142 ms 270568 KB Output is correct
102 Correct 1486 ms 339240 KB Output is correct
103 Correct 1398 ms 338792 KB Output is correct
104 Correct 1633 ms 421464 KB Output is correct
105 Correct 1093 ms 292764 KB Output is correct
106 Correct 1438 ms 437976 KB Output is correct
107 Correct 1545 ms 438168 KB Output is correct
108 Correct 1248 ms 438032 KB Output is correct
109 Correct 1315 ms 438312 KB Output is correct
110 Correct 1349 ms 438116 KB Output is correct
111 Correct 1470 ms 438004 KB Output is correct
112 Correct 1466 ms 438144 KB Output is correct
113 Correct 1273 ms 438068 KB Output is correct
114 Correct 1443 ms 438192 KB Output is correct
115 Correct 1404 ms 438208 KB Output is correct
116 Correct 1525 ms 437876 KB Output is correct