Submission #291898

# Submission time Handle Problem Language Result Execution time Memory
291898 2020-09-06T01:02:23 Z Berted Mixture (BOI20_mixture) C++14
100 / 100
339 ms 21624 KB
#include <iostream>
#include <set>
#include <map>
#include <cmath>
#define ll long long
#define pii pair<ll, ll>
#define fst first
#define snd second
#define ell __int128_t
using namespace std;

ell gcd(ell a, ell b) 
{
	return (b ? gcd(b, a % b) : a);
}

ell abs(ell a)
{
	return ((a < 0) ? -a : a);
}

/*
	We could transform the mixtures into points
	(A / (A + B + C), B / (A + B + C)) describing the ratios of the mixtures

	Observe that given X points, we can make any mixture that is 
	the convex hull of the points.

	Therefore, there are 3 possibilities :
	Answer is 1, 2, or 3.
*/

struct frac
{
	ell a, b;
	frac() {a = 0; b = 0;}
	frac(ell n, ell d)
	{
		ell g = gcd(abs(n), abs(d));
		if (g)
		{
			n /= g; d /= g;
			if (d < 0) {n = -n; d = -d;}
			if (d == 0) {n = abs(n);}
		}
		a = n; b = d;
	}

	inline frac operator-(const frac &s) const
	{
		return frac(a * s.b - b * s.a, b * s.b);
	}

	inline frac operator/(const frac &s) const
	{
		return frac(a * s.b, b * s.a);
	}

	inline bool operator<(const frac& s) const
	{
		if (b == s.b && b == 0) {return a < s.a;}
		else if (b == 0) {return 1;}
		else if (s.b == 0) {return 0;}
		else return a * s.b < b * s.a;
	}

	inline bool operator>(const frac& s) const
	{
		if (b == s.b && b == 0) {return a > s.a;}
		else if (b == 0) {return 0;}
		else if (s.b == 0) {return 1;}
		else return a * s.b > b * s.a;
	}

	inline bool operator==(const frac& s) const
	{
		if (b == s.b && b == 0) {return a == s.a;}
		else if (b == 0) {return 0;}
		else if (s.b == 0) {return 0;}
		else return a * s.b == b * s.a;
	}

	inline long double toDec()
	{
		return (long double)a / b;
	}
};

#define pdd pair<frac, frac>

inline pdd getVec(pdd p1, pdd p2) 
{
	return {p2.fst - p1.fst, p2.snd - p1.snd};
}

const long double PI = acosl(0.0) * 2;

int n, sz = 0; pdd c;
pdd ar[100001]; 
map<frac, pii> mp;
multiset<long double> s;
int suc = 0;

inline int qry()
{
	if (mp[frac(0, 0)].fst) {return 1;}
	else if (suc) {return 2;}
	else
	{
		long double f = *s.begin();
		auto it = s.upper_bound(f + PI);
		//cout << (it == s.end()) << " " << *s.begin() << " " << *it << "\n";
		if (it != s.end() && it != s.begin() && prev(it) != s.begin() && *it - *prev(it) <= PI) return 3;
	}
	return 0;
}

inline void ins(pdd p)
{
	//cout << "Insert P : " << (ll)p.fst.a << "/" << (ll)p.fst.b << ", " << (ll)p.snd.a << "/" << (ll)p.snd.b << "\n";

	ar[sz++] = p;
	p = getVec(c, p); 
	//cout << "Insert CC : " << (ll)p.fst.a << "/" << (ll)p.fst.b << ", " << (ll)p.snd.a << "/" << (ll)p.snd.b << "\n";
	//cout << "FRACFRAC : " << (ll)((p.fst / p.snd).a) << "/" << (ll)((p.fst / p.snd).b) << "\n";
	int cur = 0;
	if (p.fst.a > 0) {cur = 0;}
	else if (p.fst.a < 0) {cur = 1;}
	else if (p.snd.a >= 0) {cur = 0;}
	else {cur = 1;}
	if (cur) 
	{
		mp[p.fst / p.snd].snd++;
		if (mp[p.fst / p.snd].snd == 1 && mp[p.fst / p.snd].fst > 0) {suc++;}
	}
	else 
	{
		mp[p.fst / p.snd].fst++;
		if (mp[p.fst / p.snd].fst == 1 && mp[p.fst / p.snd].snd > 0) {suc++;}
	}
	

	//cout << "INS S : " << atan2l(p.snd.toDec(), p.fst.toDec()) << "\n";
	s.insert(atan2l(p.snd.toDec(), p.fst.toDec()));
}

inline void del(pdd p)
{
	//cout << "Delete P : " << (ll)p.fst.a << "/" << (ll)p.fst.b << ", " << (ll)p.snd.a << "/" << (ll)p.snd.b << "\n";
	p = getVec(c, p); int cur = 0;
	
	//cout << "Delete CC : " << (ll)p.fst.a << "/" << (ll)p.fst.b << ", " << (ll)p.snd.a << "/" << (ll)p.snd.b << "\n";
	//cout << "FRACFRAC : " << (ll)((p.fst / p.snd).a) << "/" << (ll)((p.fst / p.snd).b) << "\n";
	if (p.fst.a > 0) {cur = 0;}
	else if (p.fst.a < 0) {cur = 1;}
	else if (p.snd.a >= 0) {cur = 0;}
	else {cur = 1;}
	if (cur) 
	{
		mp[p.fst / p.snd].snd--;
		if (mp[p.fst / p.snd].snd == 0 && mp[p.fst / p.snd].fst > 0) {suc--;}
	}
	else 
	{
		mp[p.fst / p.snd].fst--;
		if (mp[p.fst / p.snd].fst == 0 && mp[p.fst / p.snd].snd > 0) {suc--;}
	}

	//cout << "DELET S : " << atan2l(p.snd.toDec(), p.fst.toDec()) << "\n";
	s.erase(s.find(atan2l(p.snd.toDec(), p.fst.toDec())));
}

int main()
{
	ios :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int x, y, z;
	cin >> x >> y >> z;
	c = make_pair(frac(x, x + y + z), frac(y, x + y + z));
	
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		char q; cin >> q;
		if (q == 'A')
		{
			cin >> x >> y >> z;
			ins(make_pair(frac(x, x + y + z), frac(y, x + y + z)));
		}
		else
		{
			int k; cin >> k;
			del(ar[k - 1]);
		}
		cout << qry() << '\n';
	}
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 4 ms 6656 KB Output is correct
2 Correct 4 ms 6528 KB Output is correct
3 Correct 5 ms 6528 KB Output is correct
4 Correct 4 ms 6528 KB Output is correct
5 Correct 4 ms 6528 KB Output is correct
6 Correct 4 ms 6656 KB Output is correct
7 Correct 4 ms 6656 KB Output is correct
8 Correct 4 ms 6656 KB Output is correct
9 Correct 5 ms 6656 KB Output is correct
10 Correct 4 ms 6528 KB Output is correct
11 Correct 4 ms 6528 KB Output is correct
12 Correct 4 ms 6528 KB Output is correct
13 Correct 4 ms 6656 KB Output is correct
14 Correct 5 ms 6656 KB Output is correct
15 Correct 4 ms 6528 KB Output is correct
16 Correct 4 ms 6656 KB Output is correct
17 Correct 4 ms 6656 KB Output is correct
18 Correct 4 ms 6656 KB Output is correct
19 Correct 5 ms 6528 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 6656 KB Output is correct
2 Correct 4 ms 6528 KB Output is correct
3 Correct 5 ms 6528 KB Output is correct
4 Correct 4 ms 6528 KB Output is correct
5 Correct 4 ms 6528 KB Output is correct
6 Correct 4 ms 6656 KB Output is correct
7 Correct 4 ms 6656 KB Output is correct
8 Correct 4 ms 6656 KB Output is correct
9 Correct 5 ms 6656 KB Output is correct
10 Correct 4 ms 6528 KB Output is correct
11 Correct 4 ms 6528 KB Output is correct
12 Correct 4 ms 6528 KB Output is correct
13 Correct 4 ms 6656 KB Output is correct
14 Correct 5 ms 6656 KB Output is correct
15 Correct 4 ms 6528 KB Output is correct
16 Correct 4 ms 6656 KB Output is correct
17 Correct 4 ms 6656 KB Output is correct
18 Correct 4 ms 6656 KB Output is correct
19 Correct 5 ms 6528 KB Output is correct
20 Correct 4 ms 6656 KB Output is correct
21 Correct 4 ms 6528 KB Output is correct
22 Correct 4 ms 6656 KB Output is correct
23 Correct 5 ms 6656 KB Output is correct
24 Correct 4 ms 6656 KB Output is correct
25 Correct 4 ms 6656 KB Output is correct
26 Correct 4 ms 6656 KB Output is correct
27 Correct 4 ms 6656 KB Output is correct
28 Correct 5 ms 6784 KB Output is correct
29 Correct 5 ms 6656 KB Output is correct
30 Correct 4 ms 6656 KB Output is correct
31 Correct 4 ms 6656 KB Output is correct
32 Correct 5 ms 6656 KB Output is correct
33 Correct 4 ms 6656 KB Output is correct
34 Correct 5 ms 6656 KB Output is correct
35 Correct 5 ms 6656 KB Output is correct
36 Correct 5 ms 6656 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 6656 KB Output is correct
2 Correct 4 ms 6528 KB Output is correct
3 Correct 5 ms 6528 KB Output is correct
4 Correct 4 ms 6528 KB Output is correct
5 Correct 4 ms 6528 KB Output is correct
6 Correct 4 ms 6656 KB Output is correct
7 Correct 4 ms 6656 KB Output is correct
8 Correct 4 ms 6656 KB Output is correct
9 Correct 5 ms 6656 KB Output is correct
10 Correct 4 ms 6528 KB Output is correct
11 Correct 4 ms 6528 KB Output is correct
12 Correct 4 ms 6528 KB Output is correct
13 Correct 4 ms 6656 KB Output is correct
14 Correct 5 ms 6656 KB Output is correct
15 Correct 4 ms 6528 KB Output is correct
16 Correct 4 ms 6656 KB Output is correct
17 Correct 4 ms 6656 KB Output is correct
18 Correct 4 ms 6656 KB Output is correct
19 Correct 5 ms 6528 KB Output is correct
20 Correct 4 ms 6656 KB Output is correct
21 Correct 4 ms 6528 KB Output is correct
22 Correct 4 ms 6656 KB Output is correct
23 Correct 5 ms 6656 KB Output is correct
24 Correct 4 ms 6656 KB Output is correct
25 Correct 4 ms 6656 KB Output is correct
26 Correct 4 ms 6656 KB Output is correct
27 Correct 4 ms 6656 KB Output is correct
28 Correct 5 ms 6784 KB Output is correct
29 Correct 5 ms 6656 KB Output is correct
30 Correct 4 ms 6656 KB Output is correct
31 Correct 4 ms 6656 KB Output is correct
32 Correct 5 ms 6656 KB Output is correct
33 Correct 4 ms 6656 KB Output is correct
34 Correct 5 ms 6656 KB Output is correct
35 Correct 5 ms 6656 KB Output is correct
36 Correct 5 ms 6656 KB Output is correct
37 Correct 5 ms 6656 KB Output is correct
38 Correct 5 ms 6656 KB Output is correct
39 Correct 5 ms 6656 KB Output is correct
40 Correct 6 ms 6656 KB Output is correct
41 Correct 5 ms 6656 KB Output is correct
42 Correct 5 ms 6656 KB Output is correct
43 Correct 6 ms 6656 KB Output is correct
44 Correct 6 ms 6656 KB Output is correct
45 Correct 6 ms 6656 KB Output is correct
46 Correct 10 ms 6912 KB Output is correct
47 Correct 10 ms 6912 KB Output is correct
48 Correct 7 ms 6656 KB Output is correct
49 Correct 7 ms 6656 KB Output is correct
50 Correct 7 ms 6656 KB Output is correct
51 Correct 13 ms 7040 KB Output is correct
52 Correct 11 ms 6912 KB Output is correct
53 Correct 12 ms 7168 KB Output is correct
54 Correct 13 ms 7168 KB Output is correct
55 Correct 8 ms 6784 KB Output is correct
56 Correct 8 ms 6784 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 6656 KB Output is correct
2 Correct 4 ms 6528 KB Output is correct
3 Correct 5 ms 6528 KB Output is correct
4 Correct 4 ms 6528 KB Output is correct
5 Correct 4 ms 6528 KB Output is correct
6 Correct 4 ms 6656 KB Output is correct
7 Correct 4 ms 6656 KB Output is correct
8 Correct 4 ms 6656 KB Output is correct
9 Correct 5 ms 6656 KB Output is correct
10 Correct 4 ms 6528 KB Output is correct
11 Correct 4 ms 6528 KB Output is correct
12 Correct 4 ms 6528 KB Output is correct
13 Correct 4 ms 6656 KB Output is correct
14 Correct 5 ms 6656 KB Output is correct
15 Correct 4 ms 6528 KB Output is correct
16 Correct 4 ms 6656 KB Output is correct
17 Correct 4 ms 6656 KB Output is correct
18 Correct 4 ms 6656 KB Output is correct
19 Correct 5 ms 6528 KB Output is correct
20 Correct 4 ms 6656 KB Output is correct
21 Correct 4 ms 6528 KB Output is correct
22 Correct 4 ms 6656 KB Output is correct
23 Correct 5 ms 6656 KB Output is correct
24 Correct 4 ms 6656 KB Output is correct
25 Correct 4 ms 6656 KB Output is correct
26 Correct 4 ms 6656 KB Output is correct
27 Correct 4 ms 6656 KB Output is correct
28 Correct 5 ms 6784 KB Output is correct
29 Correct 5 ms 6656 KB Output is correct
30 Correct 4 ms 6656 KB Output is correct
31 Correct 4 ms 6656 KB Output is correct
32 Correct 5 ms 6656 KB Output is correct
33 Correct 4 ms 6656 KB Output is correct
34 Correct 5 ms 6656 KB Output is correct
35 Correct 5 ms 6656 KB Output is correct
36 Correct 5 ms 6656 KB Output is correct
37 Correct 5 ms 6656 KB Output is correct
38 Correct 5 ms 6656 KB Output is correct
39 Correct 5 ms 6656 KB Output is correct
40 Correct 6 ms 6656 KB Output is correct
41 Correct 5 ms 6656 KB Output is correct
42 Correct 5 ms 6656 KB Output is correct
43 Correct 6 ms 6656 KB Output is correct
44 Correct 6 ms 6656 KB Output is correct
45 Correct 6 ms 6656 KB Output is correct
46 Correct 10 ms 6912 KB Output is correct
47 Correct 10 ms 6912 KB Output is correct
48 Correct 7 ms 6656 KB Output is correct
49 Correct 7 ms 6656 KB Output is correct
50 Correct 7 ms 6656 KB Output is correct
51 Correct 13 ms 7040 KB Output is correct
52 Correct 11 ms 6912 KB Output is correct
53 Correct 12 ms 7168 KB Output is correct
54 Correct 13 ms 7168 KB Output is correct
55 Correct 8 ms 6784 KB Output is correct
56 Correct 8 ms 6784 KB Output is correct
57 Correct 11 ms 6784 KB Output is correct
58 Correct 17 ms 7168 KB Output is correct
59 Correct 19 ms 7160 KB Output is correct
60 Correct 17 ms 7168 KB Output is correct
61 Correct 29 ms 8064 KB Output is correct
62 Correct 31 ms 8056 KB Output is correct
63 Correct 289 ms 17912 KB Output is correct
64 Correct 311 ms 17916 KB Output is correct
65 Correct 285 ms 14584 KB Output is correct
66 Correct 281 ms 14456 KB Output is correct
67 Correct 4 ms 6528 KB Output is correct
68 Correct 4 ms 6528 KB Output is correct
69 Correct 339 ms 21624 KB Output is correct
70 Correct 300 ms 18552 KB Output is correct
71 Correct 302 ms 18680 KB Output is correct
72 Correct 253 ms 17272 KB Output is correct
73 Correct 315 ms 18168 KB Output is correct