Submission #252447

# Submission time Handle Problem Language Result Execution time Memory
252447 2020-07-25T15:29:55 Z shayan_p Circle selection (APIO18_circle_selection) C++14
7 / 100
3000 ms 8440 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));
}

const int FX = 100000;

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

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

struct node{
    node *L = 0, *R = 0;
    ll bst[4];
    int lst = -1;
    node(){
	fill(bst, bst + 4, inf);
    }
    void add(int x, int l = -inf, int r = inf){ // x id e
	for(int msk = 0; msk < 4; msk++)
	    bst[msk] = -inf;
	//	for(int msk = 0; msk < 4; msk++)
	//    bst[msk] = min(bst[msk], 1ll * (bit(msk, 0) ? 1 : -1) * p[x].F.F + 1ll * (bit(msk, 1) ? 1 : -1) * p[x].F.S - 1ll * p[x].S - 1ll * p[x].S - 1ll * p[x].S - 1ll * p[x].S - 1ll * p[x].S);
	if(r-l == 1){
	    push(lst, x);
	    return;
	}
	int mid = (l+r) / 2;
	if(p[x].F.S < mid){
	    if(!L)
		L = new node();
	    L->add(x, l, mid);
	}
	else{
	    if(!R)
		R = new node();
	    R->add(x, mid, r);
	}	    
    }
    void ask(int pos, int pos2, int cof, int l = -inf, int r = inf){
	if(sz(stock) == FX)
	    return;
	if(r <= pos2){
	    if(-1ll * cof * pos + 1ll * pos2 + bst[ (cof == 1) ] > 0)
		//  if(bst[ (cof == 1) ] > 0)
		return;
	}
	if(pos2 <= l){
	    if(-1ll * cof * pos - 1ll * pos2 + bst[ (cof == 1) + 2] > 0)
		//  if(bst[ (cof == 1) + 2 ] > 0)
		return;
	}
	if(r-l == 1){
	    int pt = lst;
	    while(sz(stock) < FX && pt != -1)
		stock.insert(val[pt]), pt = fs[pt]; //////
	    return;
	}
	int mid = (l+r) / 2;
	if(L)
	    L->ask(pos, pos2, cof, l, mid);
	if(R)
	    R->ask(pos, pos2, cof, mid, r);	    
    }
};
struct node2{
    node2 *L = 0, *R = 0;
    node* seg = 0;
    void add(int x, int l = -inf, int r = inf){
	if(!seg)
	    seg = new node();
	seg->add(x);
	if(r-l == 1)
	    return;
	int mid = (l+r) / 2;
	if(p[x].F.F < mid){
	    if(!L)
		L = new node2();
	    L->add(x, l, mid);
	}
	else{
	    if(!R)
		R = new node2();
	    R->add(x, mid, r);
	}	    
    }
    void ask(int pos, int pos2, int l = -inf, int r = inf){
	if(r <= pos){
	    if(seg)
		seg->ask(pos, pos2, -1);
	    return;
	}
	if(pos <= l){
	    if(seg)
		seg->ask(pos, pos2, 1);
	    return;
	}
	int mid = (l+r) / 2;
	if(L)
	    L->ask(pos, pos2, l, mid);
	if(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];
	//	cout << "IN " << I + 1 << endl;
	//	stock.clear();
	//	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(I);


	    stock.insert(I);
	}
    }
    for(int i = 0; i < n; i++){
	cout << ans[i] << " ";
    }
    return cout << endl, 0;
}

Compilation message

circle_selection.cpp: In function 'int main()':
circle_selection.cpp:143:12: warning: unused variable 'root' [-Wunused-variable]
     node2* root = new node2();
            ^~~~
# Verdict Execution time Memory 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 0 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 0 ms 400 KB Output is correct
10 Correct 1 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 1 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 4 ms 640 KB Output is correct
20 Correct 3 ms 640 KB Output is correct
21 Correct 4 ms 640 KB Output is correct
22 Correct 169 ms 888 KB Output is correct
23 Correct 161 ms 888 KB Output is correct
24 Correct 177 ms 1016 KB Output is correct
25 Correct 163 ms 888 KB Output is correct
26 Correct 162 ms 888 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 181 ms 8312 KB Output is correct
2 Correct 190 ms 8264 KB Output is correct
3 Correct 182 ms 8056 KB Output is correct
4 Correct 178 ms 8440 KB Output is correct
5 Execution timed out 3073 ms 6700 KB Time limit exceeded
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Execution timed out 3071 ms 3532 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3070 ms 6504 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory 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 0 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 0 ms 400 KB Output is correct
10 Correct 1 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 1 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 4 ms 640 KB Output is correct
20 Correct 3 ms 640 KB Output is correct
21 Correct 4 ms 640 KB Output is correct
22 Correct 169 ms 888 KB Output is correct
23 Correct 161 ms 888 KB Output is correct
24 Correct 177 ms 1016 KB Output is correct
25 Correct 163 ms 888 KB Output is correct
26 Correct 162 ms 888 KB Output is correct
27 Correct 7 ms 896 KB Output is correct
28 Correct 7 ms 896 KB Output is correct
29 Correct 8 ms 896 KB Output is correct
30 Correct 785 ms 1400 KB Output is correct
31 Correct 765 ms 1528 KB Output is correct
32 Correct 748 ms 1400 KB Output is correct
33 Correct 69 ms 3192 KB Output is correct
34 Correct 69 ms 3192 KB Output is correct
35 Correct 70 ms 3192 KB Output is correct
36 Execution timed out 3072 ms 3764 KB Time limit exceeded
37 Halted 0 ms 0 KB -
# Verdict Execution time Memory 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 0 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 0 ms 400 KB Output is correct
10 Correct 1 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 1 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 4 ms 640 KB Output is correct
20 Correct 3 ms 640 KB Output is correct
21 Correct 4 ms 640 KB Output is correct
22 Correct 169 ms 888 KB Output is correct
23 Correct 161 ms 888 KB Output is correct
24 Correct 177 ms 1016 KB Output is correct
25 Correct 163 ms 888 KB Output is correct
26 Correct 162 ms 888 KB Output is correct
27 Correct 181 ms 8312 KB Output is correct
28 Correct 190 ms 8264 KB Output is correct
29 Correct 182 ms 8056 KB Output is correct
30 Correct 178 ms 8440 KB Output is correct
31 Execution timed out 3073 ms 6700 KB Time limit exceeded
32 Halted 0 ms 0 KB -