Submission #123215

# Submission time Handle Problem Language Result Execution time Memory
123215 2019-06-30T12:02:46 Z tmwilliamlin168 Relay (COI16_relay) C++14
100 / 100
95 ms 9128 KB
#include <bits/stdc++.h>
using namespace std;

#define ll long long

const int mxN=1e5;
int n, m, ans;
ll xa[mxN], ya[mxN], xb[2*mxN], yb[2*mxN];

struct ts {
	int li, ri;
	ll lx, ly, rx, ry;
};

ll cp(ll x1, ll y1, ll x2, ll y2, ll x3, ll y3) {
	return (y3-y1)*(x2-x1)-(y2-y1)*(x3-x1);
}

ts gts(ll x, ll y) {
	ts r;
	if(cp(x, y, xb[m-1], yb[m-1], xb[0], yb[0])<0) {
		//cout << x << " " << y << endl;
		int lb=0, rb=m-2;
		while(lb<rb) {
			int mb=(lb+rb+1)/2;
			if(cp(x, y, xb[m-1], yb[m-1], xb[mb], yb[mb])<0&&cp(x, y, xb[mb-1], yb[mb-1], xb[mb], yb[mb])<0)
				lb=mb;
			else
				rb=mb-1;
		}
		r.ri=lb;
		lb=1, rb=m-1;
		while(lb<rb) {
			int mb=(lb+rb)/2;
			if(cp(x, y, xb[mb], yb[mb], xb[0], yb[0])<0&&cp(x, y, xb[mb], yb[mb], xb[mb+1], yb[mb+1])<0)
				rb=mb;
			else
				lb=mb+1;
		}
		r.li=lb;
	} else {
		//cout << "gt " << x << " " << y << endl;
		int lb=0, rb=m-2;
		while(lb<rb) {
			int mb=(lb+rb+1)/2;
			if(cp(x, y, xb[m-1], yb[m-1], xb[mb], yb[mb])>=0&&cp(x, y, xb[mb-1], yb[mb-1], xb[mb], yb[mb])>=0)
				lb=mb;
			else
				rb=mb-1;
		}
		r.li=lb;
		lb=1, rb=m-1;
		while(lb<rb) {
			int mb=(lb+rb)/2;
			if(cp(x, y, xb[mb], yb[mb], xb[0], yb[0])>=0&&cp(x, y, xb[mb], yb[mb], xb[mb+1], yb[mb+1])>=0)
				rb=mb;
			else
				lb=mb+1;
		}
		r.ri=lb;
	}
	r.lx=r.rx=x;
	r.ly=r.ry=y;
	return r;
}

bool wt(ll x, ll y, ts t) {
	return t.li>t.ri&&cp(xb[t.li], yb[t.li], xb[t.ri], yb[t.ri], x, y)>0&&cp(t.lx, t.ly, xb[t.li], yb[t.li], x, y)<0&&cp(t.rx, t.ry, xb[t.ri], yb[t.ri], x, y)>0;
}

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);

	cin >> n;
	for(int i=0; i<n; ++i)
		cin >> xa[i] >> ya[i];
	cin >> m;
	for(int i=0; i<m; ++i)
		cin >> xb[i] >> yb[i];
	memcpy(xb+m, xb, 8*m);
	memcpy(yb+m, yb, 8*m);
	ts re1=gts(xa[0], ya[0]);
	if(re1.li<re1.ri)
		re1.li+=m;
	//cout << re1.li << " " << re1.ri << endl;
	ts re2=re1;
	for(int i=1; i<n; ++i) {
		ts tr=gts(xa[i], ya[i]);
		//cout << tr.li << " " << tr.ri << endl;
		if(cp(xa[0], ya[0], xb[re1.li], yb[re1.li], xa[i], ya[i])>=0) {
			//cout << "l " << i << endl;
			if(tr.li+m<=re1.li)
				tr.li+=m;
			if(tr.li^re2.li?tr.li<re2.li:cp(re2.lx, re2.ly, xb[tr.li], yb[tr.li], tr.lx, tr.ly)>0) {
				re2.li=tr.li;
				re2.lx=tr.lx;
				re2.ly=tr.ly;
			}
		}
		if(cp(xa[0], ya[0], xb[re1.ri], yb[re1.ri], xa[i], ya[i])<=0) {
			//cout << "r " << i << endl;
			if(tr.ri<re1.ri)
				tr.ri+=m;
			if(tr.ri^re2.ri?tr.ri>re2.ri:cp(re2.rx, re2.ry, xb[tr.ri], yb[tr.ri], tr.rx, tr.ry)<0) {
				re2.ri=tr.ri;
				re2.rx=tr.rx;
				re2.ry=tr.ry;
			}
		}
	}
	for(int i=1; i<n; ++i)
		ans+=!wt(xa[i], ya[i], re2);
	cout << ans;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 380 KB Output is correct
2 Correct 2 ms 504 KB Output is correct
3 Correct 2 ms 396 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 504 KB Output is correct
6 Correct 2 ms 380 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 348 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 380 KB Output is correct
2 Correct 2 ms 504 KB Output is correct
3 Correct 2 ms 396 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 504 KB Output is correct
6 Correct 2 ms 380 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 348 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 5 ms 632 KB Output is correct
12 Correct 5 ms 632 KB Output is correct
13 Correct 4 ms 504 KB Output is correct
14 Correct 4 ms 504 KB Output is correct
15 Correct 4 ms 508 KB Output is correct
16 Correct 4 ms 504 KB Output is correct
17 Correct 4 ms 508 KB Output is correct
18 Correct 4 ms 508 KB Output is correct
19 Correct 4 ms 504 KB Output is correct
20 Correct 4 ms 504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 380 KB Output is correct
2 Correct 2 ms 504 KB Output is correct
3 Correct 2 ms 396 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 504 KB Output is correct
6 Correct 2 ms 380 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 348 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 45 ms 3960 KB Output is correct
12 Correct 47 ms 3928 KB Output is correct
13 Correct 42 ms 3960 KB Output is correct
14 Correct 45 ms 3960 KB Output is correct
15 Correct 51 ms 3832 KB Output is correct
16 Correct 49 ms 3960 KB Output is correct
17 Correct 50 ms 3912 KB Output is correct
18 Correct 50 ms 3960 KB Output is correct
19 Correct 51 ms 3832 KB Output is correct
20 Correct 51 ms 3968 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 380 KB Output is correct
2 Correct 2 ms 504 KB Output is correct
3 Correct 2 ms 396 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 504 KB Output is correct
6 Correct 2 ms 380 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 348 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 5 ms 632 KB Output is correct
12 Correct 5 ms 632 KB Output is correct
13 Correct 4 ms 504 KB Output is correct
14 Correct 4 ms 504 KB Output is correct
15 Correct 4 ms 508 KB Output is correct
16 Correct 4 ms 504 KB Output is correct
17 Correct 4 ms 508 KB Output is correct
18 Correct 4 ms 508 KB Output is correct
19 Correct 4 ms 504 KB Output is correct
20 Correct 4 ms 504 KB Output is correct
21 Correct 45 ms 3960 KB Output is correct
22 Correct 47 ms 3928 KB Output is correct
23 Correct 42 ms 3960 KB Output is correct
24 Correct 45 ms 3960 KB Output is correct
25 Correct 51 ms 3832 KB Output is correct
26 Correct 49 ms 3960 KB Output is correct
27 Correct 50 ms 3912 KB Output is correct
28 Correct 50 ms 3960 KB Output is correct
29 Correct 51 ms 3832 KB Output is correct
30 Correct 51 ms 3968 KB Output is correct
31 Correct 92 ms 9128 KB Output is correct
32 Correct 92 ms 8952 KB Output is correct
33 Correct 74 ms 6536 KB Output is correct
34 Correct 74 ms 6472 KB Output is correct
35 Correct 94 ms 6380 KB Output is correct
36 Correct 95 ms 6520 KB Output is correct
37 Correct 93 ms 6420 KB Output is correct
38 Correct 95 ms 6524 KB Output is correct
39 Correct 95 ms 6264 KB Output is correct
40 Correct 95 ms 6220 KB Output is correct