Submission #257264

# Submission time Handle Problem Language Result Execution time Memory
257264 2020-08-04T03:02:45 Z maximath_1 Mixture (BOI20_mixture) C++11
100 / 100
394 ms 8548 KB
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define pt pair<ll, ll>

int sign(ll x){
	if(x > 0) return 1;
	if(x < 0) return -1;
	return 0;
}
int half(pt x){
	if(x.second != 0)
		return sign(x.second);
	return -sign(x.first);
}

__int128_t cross(pt a, pt b){
	return (__int128_t)a.first * b.second - (__int128_t)a.second * b.first;
}
bool angCmp(pt a, pt b){
	int A = half(a), B = half(b);
	if(A == B) return cross(a, b) > 0;
	return A < B;
}

typedef array<ll, 3> T;

T a;
int eq = 0, neg = 0;
vector<pt> cat;

struct cmp{
	bool operator()(const pt&a, const pt&b) const{
		return angCmp(a, b);
	}
};

map<pair<ll, ll>, int, cmp> mp;

T operator*(T a, ll b){
	for(int i = 0; i < 3; i ++) 
		a[i] *= b;
	return a;
}
T operator+(T a, T b){
	for(int i = 0; i < 3; i ++)
		a[i] += b[i];
	return a;
}
T operator-(T a, T b){
	for(int i = 0; i < 3; i ++)
		a[i] -= b[i];
	return a;
}
ll sum(T a){return a[0] + a[1] + a[2];}

ll dot(T a, T b){
	ll res = 0;
	for(int i = 0; i < 3; i ++)
		res += a[i] * b[i];
	return res;
}

pair<ll, ll> lst;

bool bad(pt a, pt b){
	return a == b || cross(a, b) < 0;
}

void add(pair<ll, ll> p, int x){
	if(p.first == 0 && p.second == 0){
		eq += x; return;
	}
	vector<pair<ll, ll> > cand = {lst, p};
	if(x == 1){
		if(!mp.count(p) && mp.count({-p.first, -p.second})) neg ++;
		mp[p] ++;
	}else{
		if(mp[p] == 1 && mp.count({-p.first, -p.second})) neg --;
		auto it = mp.find(p);
		if(it == mp.begin()) it = mp.end();
		it --; cand.push_back(it -> first);
		mp[p] --;
		if(!mp[p]) mp.erase(p);
	}

	lst = {0, 0};
	for(pair<ll, ll> i : cand){
		auto it = mp.find(i);
		if(it == mp.end()) continue;
		auto nx = next(it);
		if(nx == mp.end()) nx = mp.begin();

		if(bad(i, nx -> first))
			lst = i;
	}
}

int ans(){
	if(eq) return 1;
	if(neg) return 2;
	if(mp.size() && lst.first == 0 && lst.second == 0)
		return 3;
	return 0;
}

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

	long long rd;
	cin >> rd; a[0] = rd;
	cin >> rd; a[1] = rd;
	cin >> rd; a[2] = rd;
	int q; cin >> q;
	for(char c; q --;){
		cin >> c;
		if(c == 'A'){
			T x;
			cin >> rd; x[0] = rd;
			cin >> rd; x[1] = rd;
			cin >> rd; x[2] = rd;
			
			x = x * sum(a) - a * sum(x);
			pt p = {dot(x, {1, -1, 0}), dot(x, {1, 1, -2})};
			ll gc = __gcd(abs(p.first), abs(p.second));
			if(p.first || p.second) p.first /= gc, p.second /= gc;
			cat.push_back(p);
			add(cat.back(), 1);
		}else{
			int r; cin >> r; r --;
			add(cat[r], -1);
		}
		ll get = (ll)ans();
		cout << get << endl;
	}
	return 0;
}
# 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 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 0 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 0 ms 384 KB Output is correct
18 Correct 0 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
# 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 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 0 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 0 ms 384 KB Output is correct
18 Correct 0 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 2 ms 384 KB Output is correct
24 Correct 1 ms 360 KB Output is correct
25 Correct 2 ms 384 KB Output is correct
26 Correct 2 ms 384 KB Output is correct
27 Correct 2 ms 384 KB Output is correct
28 Correct 2 ms 384 KB Output is correct
29 Correct 1 ms 384 KB Output is correct
30 Correct 2 ms 384 KB Output is correct
31 Correct 1 ms 384 KB Output is correct
32 Correct 2 ms 384 KB Output is correct
33 Correct 2 ms 384 KB Output is correct
34 Correct 2 ms 384 KB Output is correct
35 Correct 2 ms 384 KB Output is correct
36 Correct 2 ms 384 KB Output is correct
# 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 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 0 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 0 ms 384 KB Output is correct
18 Correct 0 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 2 ms 384 KB Output is correct
24 Correct 1 ms 360 KB Output is correct
25 Correct 2 ms 384 KB Output is correct
26 Correct 2 ms 384 KB Output is correct
27 Correct 2 ms 384 KB Output is correct
28 Correct 2 ms 384 KB Output is correct
29 Correct 1 ms 384 KB Output is correct
30 Correct 2 ms 384 KB Output is correct
31 Correct 1 ms 384 KB Output is correct
32 Correct 2 ms 384 KB Output is correct
33 Correct 2 ms 384 KB Output is correct
34 Correct 2 ms 384 KB Output is correct
35 Correct 2 ms 384 KB Output is correct
36 Correct 2 ms 384 KB Output is correct
37 Correct 3 ms 384 KB Output is correct
38 Correct 3 ms 384 KB Output is correct
39 Correct 3 ms 384 KB Output is correct
40 Correct 4 ms 384 KB Output is correct
41 Correct 4 ms 384 KB Output is correct
42 Correct 5 ms 384 KB Output is correct
43 Correct 4 ms 384 KB Output is correct
44 Correct 4 ms 384 KB Output is correct
45 Correct 4 ms 384 KB Output is correct
46 Correct 18 ms 512 KB Output is correct
47 Correct 12 ms 512 KB Output is correct
48 Correct 8 ms 384 KB Output is correct
49 Correct 9 ms 488 KB Output is correct
50 Correct 9 ms 384 KB Output is correct
51 Correct 16 ms 512 KB Output is correct
52 Correct 14 ms 640 KB Output is correct
53 Correct 15 ms 640 KB Output is correct
54 Correct 15 ms 640 KB Output is correct
55 Correct 14 ms 512 KB Output is correct
56 Correct 12 ms 512 KB Output is correct
# 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 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 0 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 0 ms 384 KB Output is correct
18 Correct 0 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 2 ms 384 KB Output is correct
24 Correct 1 ms 360 KB Output is correct
25 Correct 2 ms 384 KB Output is correct
26 Correct 2 ms 384 KB Output is correct
27 Correct 2 ms 384 KB Output is correct
28 Correct 2 ms 384 KB Output is correct
29 Correct 1 ms 384 KB Output is correct
30 Correct 2 ms 384 KB Output is correct
31 Correct 1 ms 384 KB Output is correct
32 Correct 2 ms 384 KB Output is correct
33 Correct 2 ms 384 KB Output is correct
34 Correct 2 ms 384 KB Output is correct
35 Correct 2 ms 384 KB Output is correct
36 Correct 2 ms 384 KB Output is correct
37 Correct 3 ms 384 KB Output is correct
38 Correct 3 ms 384 KB Output is correct
39 Correct 3 ms 384 KB Output is correct
40 Correct 4 ms 384 KB Output is correct
41 Correct 4 ms 384 KB Output is correct
42 Correct 5 ms 384 KB Output is correct
43 Correct 4 ms 384 KB Output is correct
44 Correct 4 ms 384 KB Output is correct
45 Correct 4 ms 384 KB Output is correct
46 Correct 18 ms 512 KB Output is correct
47 Correct 12 ms 512 KB Output is correct
48 Correct 8 ms 384 KB Output is correct
49 Correct 9 ms 488 KB Output is correct
50 Correct 9 ms 384 KB Output is correct
51 Correct 16 ms 512 KB Output is correct
52 Correct 14 ms 640 KB Output is correct
53 Correct 15 ms 640 KB Output is correct
54 Correct 15 ms 640 KB Output is correct
55 Correct 14 ms 512 KB Output is correct
56 Correct 12 ms 512 KB Output is correct
57 Correct 18 ms 640 KB Output is correct
58 Correct 23 ms 716 KB Output is correct
59 Correct 25 ms 640 KB Output is correct
60 Correct 22 ms 632 KB Output is correct
61 Correct 53 ms 1400 KB Output is correct
62 Correct 59 ms 1404 KB Output is correct
63 Correct 382 ms 6764 KB Output is correct
64 Correct 363 ms 6632 KB Output is correct
65 Correct 373 ms 4608 KB Output is correct
66 Correct 367 ms 4204 KB Output is correct
67 Correct 0 ms 384 KB Output is correct
68 Correct 0 ms 384 KB Output is correct
69 Correct 394 ms 8548 KB Output is correct
70 Correct 359 ms 7148 KB Output is correct
71 Correct 350 ms 7148 KB Output is correct
72 Correct 339 ms 6256 KB Output is correct
73 Correct 367 ms 6764 KB Output is correct