답안 #252525

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
252525 2020-07-25T18:27:16 Z shayan_p 원 고르기 (APIO18_circle_selection) C++14
87 / 100
3000 ms 167872 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;

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));
}

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{
    map<int, int> mp;
    map<int, int> :: iterator it;
    node(){
	it = mp.end();
    }
    void add(int pos, int x){
	mp[pos] = x;
    }
    void ask(int pos){
	bool A = it == mp.begin() || (prev(it)->F) < pos;
	bool B = it == mp.end() || (it->F) >= pos;
	if(!A || !B)	    
	    it = mp.lower_bound(pos);
	if(it != mp.end())
	    stock.PB(it->S);
	if(it != mp.begin())
	    stock.PB(prev(it)->S);
    }
};
struct node2{
    node2 *L = 0, *R = 0;
    node* seg = 0;
    void add(int f, int s, int pos, int x, int l = 0, int r = sz(vx)-1){
	if(f <= vx[l] && vx[r] <= s){
	    if(!seg)
		seg = new node();
	    seg->add(pos, 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, pos, x, l, mid);
	}
	if(max(f, vx[mid]) < min(s, vx[r])){
	    if(!R)
		R = new node2();
	    R->add(f, s, pos, 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();
	for(int w2 = -1; w2 <= 1; w2++){
	    for(int w = -1; w <= 1; w++){
		if((w != 0 || w2 != 0))
		    root->ask(p[I].F.F + w * p[I].S, p[I].F.S + w2 * p[I].S); // kafie?
	    }
	}
	for(int id : stock){
	    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, 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 0 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 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 0 ms 256 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 0 ms 384 KB Output is correct
14 Correct 0 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 2 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 6 ms 640 KB Output is correct
20 Correct 6 ms 640 KB Output is correct
21 Correct 6 ms 640 KB Output is correct
22 Correct 12 ms 2048 KB Output is correct
23 Correct 21 ms 3072 KB Output is correct
24 Correct 12 ms 1920 KB Output is correct
25 Correct 10 ms 1664 KB Output is correct
26 Correct 13 ms 1920 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 364 ms 13264 KB Output is correct
2 Correct 394 ms 13368 KB Output is correct
3 Correct 388 ms 13004 KB Output is correct
4 Correct 370 ms 13252 KB Output is correct
5 Correct 665 ms 17432 KB Output is correct
6 Correct 901 ms 52680 KB Output is correct
7 Correct 769 ms 23616 KB Output is correct
8 Correct 814 ms 32204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 559 ms 53432 KB Output is correct
3 Correct 1848 ms 156608 KB Output is correct
4 Correct 1858 ms 156124 KB Output is correct
5 Correct 2345 ms 140984 KB Output is correct
6 Correct 942 ms 58196 KB Output is correct
7 Correct 363 ms 28004 KB Output is correct
8 Correct 41 ms 4468 KB Output is correct
9 Correct 2032 ms 157684 KB Output is correct
10 Correct 2974 ms 124868 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1500 ms 145600 KB Output is correct
2 Correct 806 ms 74184 KB Output is correct
3 Correct 2522 ms 30924 KB Output is correct
4 Correct 907 ms 84208 KB Output is correct
5 Correct 861 ms 78760 KB Output is correct
6 Correct 1806 ms 17228 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 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 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 0 ms 256 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 0 ms 384 KB Output is correct
14 Correct 0 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 2 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 6 ms 640 KB Output is correct
20 Correct 6 ms 640 KB Output is correct
21 Correct 6 ms 640 KB Output is correct
22 Correct 12 ms 2048 KB Output is correct
23 Correct 21 ms 3072 KB Output is correct
24 Correct 12 ms 1920 KB Output is correct
25 Correct 10 ms 1664 KB Output is correct
26 Correct 13 ms 1920 KB Output is correct
27 Correct 12 ms 896 KB Output is correct
28 Correct 12 ms 896 KB Output is correct
29 Correct 12 ms 896 KB Output is correct
30 Correct 38 ms 5112 KB Output is correct
31 Correct 25 ms 3840 KB Output is correct
32 Correct 25 ms 3712 KB Output is correct
33 Correct 124 ms 4704 KB Output is correct
34 Correct 124 ms 4708 KB Output is correct
35 Correct 139 ms 4708 KB Output is correct
36 Correct 383 ms 39304 KB Output is correct
37 Correct 396 ms 40036 KB Output is correct
38 Correct 405 ms 44000 KB Output is correct
39 Correct 353 ms 7776 KB Output is correct
40 Correct 355 ms 7652 KB Output is correct
41 Correct 355 ms 7652 KB Output is correct
42 Correct 361 ms 7584 KB Output is correct
43 Correct 250 ms 24568 KB Output is correct
44 Correct 265 ms 24676 KB Output is correct
45 Correct 256 ms 24692 KB Output is correct
46 Correct 267 ms 24672 KB Output is correct
47 Correct 260 ms 24628 KB Output is correct
48 Correct 256 ms 24544 KB Output is correct
49 Correct 250 ms 24544 KB Output is correct
50 Correct 248 ms 24676 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 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 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 0 ms 256 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 0 ms 384 KB Output is correct
14 Correct 0 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 2 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 6 ms 640 KB Output is correct
20 Correct 6 ms 640 KB Output is correct
21 Correct 6 ms 640 KB Output is correct
22 Correct 12 ms 2048 KB Output is correct
23 Correct 21 ms 3072 KB Output is correct
24 Correct 12 ms 1920 KB Output is correct
25 Correct 10 ms 1664 KB Output is correct
26 Correct 13 ms 1920 KB Output is correct
27 Correct 364 ms 13264 KB Output is correct
28 Correct 394 ms 13368 KB Output is correct
29 Correct 388 ms 13004 KB Output is correct
30 Correct 370 ms 13252 KB Output is correct
31 Correct 665 ms 17432 KB Output is correct
32 Correct 901 ms 52680 KB Output is correct
33 Correct 769 ms 23616 KB Output is correct
34 Correct 814 ms 32204 KB Output is correct
35 Correct 0 ms 384 KB Output is correct
36 Correct 559 ms 53432 KB Output is correct
37 Correct 1848 ms 156608 KB Output is correct
38 Correct 1858 ms 156124 KB Output is correct
39 Correct 2345 ms 140984 KB Output is correct
40 Correct 942 ms 58196 KB Output is correct
41 Correct 363 ms 28004 KB Output is correct
42 Correct 41 ms 4468 KB Output is correct
43 Correct 2032 ms 157684 KB Output is correct
44 Correct 2974 ms 124868 KB Output is correct
45 Correct 1500 ms 145600 KB Output is correct
46 Correct 806 ms 74184 KB Output is correct
47 Correct 2522 ms 30924 KB Output is correct
48 Correct 907 ms 84208 KB Output is correct
49 Correct 861 ms 78760 KB Output is correct
50 Correct 1806 ms 17228 KB Output is correct
51 Correct 12 ms 896 KB Output is correct
52 Correct 12 ms 896 KB Output is correct
53 Correct 12 ms 896 KB Output is correct
54 Correct 38 ms 5112 KB Output is correct
55 Correct 25 ms 3840 KB Output is correct
56 Correct 25 ms 3712 KB Output is correct
57 Correct 124 ms 4704 KB Output is correct
58 Correct 124 ms 4708 KB Output is correct
59 Correct 139 ms 4708 KB Output is correct
60 Correct 383 ms 39304 KB Output is correct
61 Correct 396 ms 40036 KB Output is correct
62 Correct 405 ms 44000 KB Output is correct
63 Correct 353 ms 7776 KB Output is correct
64 Correct 355 ms 7652 KB Output is correct
65 Correct 355 ms 7652 KB Output is correct
66 Correct 361 ms 7584 KB Output is correct
67 Correct 250 ms 24568 KB Output is correct
68 Correct 265 ms 24676 KB Output is correct
69 Correct 256 ms 24692 KB Output is correct
70 Correct 267 ms 24672 KB Output is correct
71 Correct 260 ms 24628 KB Output is correct
72 Correct 256 ms 24544 KB Output is correct
73 Correct 250 ms 24544 KB Output is correct
74 Correct 248 ms 24676 KB Output is correct
75 Correct 442 ms 12976 KB Output is correct
76 Correct 426 ms 13376 KB Output is correct
77 Correct 383 ms 13388 KB Output is correct
78 Correct 391 ms 13000 KB Output is correct
79 Correct 836 ms 15060 KB Output is correct
80 Correct 409 ms 13380 KB Output is correct
81 Correct 1818 ms 150612 KB Output is correct
82 Correct 1473 ms 138432 KB Output is correct
83 Correct 1500 ms 139176 KB Output is correct
84 Correct 2165 ms 167872 KB Output is correct
85 Correct 1607 ms 146636 KB Output is correct
86 Correct 1432 ms 135756 KB Output is correct
87 Execution timed out 3107 ms 166600 KB Time limit exceeded
88 Halted 0 ms 0 KB -