답안 #252402

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
252402 2020-07-25T12:59:52 Z shayan_p 원 고르기 (APIO18_circle_selection) C++14
7 / 100
1665 ms 1048580 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;

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 = 5010;

vector<int> val, fs;
vector<int> stock;

void push(int &lst, int x){
    fs.PB(lst);
    lst = sz(val);
    val.PB(x);
}

struct node{
    node *L = 0, *R = 0;
    int lst = -1;
    void add(int f, int s, int x, int l, int r){
	if(f <= l && r <= s){
	    push(lst, x);
	    return;
	}
	if(r-l == 1)
	    return;
	int mid = (l+r) / 2;	
	if(max(f, l) < min(s, mid)){
	    if(!L)
		L = new node();
	    L->add(f, s, x, l, mid);
	}
	if(max(f, mid) < min(s, r)){
	    if(!R)
		R = new node();
	    R->add(f, s, x, mid, r);
	}
    }
    void ask(int pos, int l, int r){
	if(sz(stock) == FX)
	    return;
	int pt = lst;
	while(sz(stock) < FX && pt != -1){
	    stock.PB(val[pt]);
	    pt = fs[pt];
	}
	if(r-l == 1)
	    return;
	int mid = (l+r) / 2;
	if(pos < mid && L)
	    L->ask(pos, l, mid);
	if(mid <= pos && R)
	    R->ask(pos, mid, r);	    
    }
};
struct node2{
    node2 *L = 0, *R = 0;
    node* seg = 0;
    void add(int f, int s, int f2, int s2, int x, int l, int r){
	if(f <= l && r <= s){
	    if(!seg)
		seg = new node();
	    seg->add(f2, s2, x, -inf, inf);
	    return;
	}
	if(r-l == 1)
	    return;
	int mid = (l+r) / 2;	
	if(max(f, l) < min(s, mid)){
	    if(!L)
		L = new node2();
	    L->add(f, s, f2, s2, x, l, mid);
	}
	if(max(f, mid) < min(s, r)){
	    if(!R)
		R = new node2();
	    R->add(f, s, f2, s2, x, mid, r);
	}
    }
    void ask(int pos, int pos2, int l, int r){
	if(seg)
	    seg->ask(pos2, -inf, inf);
	if(r-l == 1)
	    return;
	int mid = (l+r) / 2;
	if(pos < mid && L)
	    L->ask(pos, pos2, l, mid);
	if(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;
	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);
    for(int i = n-1; i >= 0; i--){
	int I = arr[i];
	stock.clear();
	root->ask(p[I].F.F, p[I].F.S, -inf, inf);
	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( int( max(ll(-inf), 1ll * p[I].F.F - 2ll * p[I].S) ),
		       int( min(ll(inf), 1ll * p[I].F.F + 2ll * p[I].S + 1) ),
		       int ( max(ll(-inf), 1ll * p[I].F.S - 2ll * p[I].S) ),
		       int( min(ll(inf), 1ll * p[I].F.S + 2ll * p[I].S + 1) ),
		       I,
		       -inf,
		       inf
		       );
	}
    }
    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 512 KB Output is correct
3 Correct 1 ms 512 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 512 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 6 ms 3584 KB Output is correct
12 Correct 4 ms 3200 KB Output is correct
13 Correct 5 ms 3456 KB Output is correct
14 Correct 5 ms 3712 KB Output is correct
15 Correct 5 ms 3584 KB Output is correct
16 Correct 1 ms 640 KB Output is correct
17 Correct 1 ms 512 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 4 ms 512 KB Output is correct
20 Correct 3 ms 512 KB Output is correct
21 Correct 4 ms 896 KB Output is correct
22 Correct 215 ms 146104 KB Output is correct
23 Correct 180 ms 117692 KB Output is correct
24 Correct 225 ms 157224 KB Output is correct
25 Correct 185 ms 131392 KB Output is correct
26 Correct 216 ms 153532 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 185 ms 8500 KB Output is correct
2 Correct 211 ms 8700 KB Output is correct
3 Correct 189 ms 8252 KB Output is correct
4 Correct 177 ms 8504 KB Output is correct
5 Correct 599 ms 74088 KB Output is correct
6 Runtime error 1665 ms 1048580 KB Execution killed with signal 9 (could be triggered by violating memory limits)
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1280 KB Output is correct
2 Runtime error 1559 ms 1048580 KB Execution killed with signal 9 (could be triggered by violating memory limits)
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1580 ms 1048580 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 512 KB Output is correct
3 Correct 1 ms 512 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 512 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 6 ms 3584 KB Output is correct
12 Correct 4 ms 3200 KB Output is correct
13 Correct 5 ms 3456 KB Output is correct
14 Correct 5 ms 3712 KB Output is correct
15 Correct 5 ms 3584 KB Output is correct
16 Correct 1 ms 640 KB Output is correct
17 Correct 1 ms 512 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 4 ms 512 KB Output is correct
20 Correct 3 ms 512 KB Output is correct
21 Correct 4 ms 896 KB Output is correct
22 Correct 215 ms 146104 KB Output is correct
23 Correct 180 ms 117692 KB Output is correct
24 Correct 225 ms 157224 KB Output is correct
25 Correct 185 ms 131392 KB Output is correct
26 Correct 216 ms 153532 KB Output is correct
27 Correct 8 ms 1152 KB Output is correct
28 Correct 6 ms 640 KB Output is correct
29 Correct 6 ms 640 KB Output is correct
30 Correct 434 ms 296596 KB Output is correct
31 Correct 455 ms 299944 KB Output is correct
32 Correct 400 ms 284840 KB Output is correct
33 Correct 63 ms 3064 KB Output is correct
34 Correct 67 ms 2936 KB Output is correct
35 Correct 79 ms 7792 KB Output is correct
36 Runtime error 1493 ms 1048580 KB Execution killed with signal 9 (could be triggered by violating memory limits)
37 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 512 KB Output is correct
3 Correct 1 ms 512 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 512 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 6 ms 3584 KB Output is correct
12 Correct 4 ms 3200 KB Output is correct
13 Correct 5 ms 3456 KB Output is correct
14 Correct 5 ms 3712 KB Output is correct
15 Correct 5 ms 3584 KB Output is correct
16 Correct 1 ms 640 KB Output is correct
17 Correct 1 ms 512 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 4 ms 512 KB Output is correct
20 Correct 3 ms 512 KB Output is correct
21 Correct 4 ms 896 KB Output is correct
22 Correct 215 ms 146104 KB Output is correct
23 Correct 180 ms 117692 KB Output is correct
24 Correct 225 ms 157224 KB Output is correct
25 Correct 185 ms 131392 KB Output is correct
26 Correct 216 ms 153532 KB Output is correct
27 Correct 185 ms 8500 KB Output is correct
28 Correct 211 ms 8700 KB Output is correct
29 Correct 189 ms 8252 KB Output is correct
30 Correct 177 ms 8504 KB Output is correct
31 Correct 599 ms 74088 KB Output is correct
32 Runtime error 1665 ms 1048580 KB Execution killed with signal 9 (could be triggered by violating memory limits)
33 Halted 0 ms 0 KB -