# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1185480 | steveonalex | Mixture (BOI20_mixture) | C++20 | 0 ms | 0 KiB |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define MASK(i) (1ULL << (i))
#define GETBIT(mask, i) (((mask) >> (i)) & 1)
#define ALL(v) (v).begin(), (v).end()
ll max(ll a, ll b){return (a > b) ? a : b;}
ll min(ll a, ll b){return (a < b) ? a : b;}
ll gcd(ll a, ll b){return __gcd(abs(a), abs(b));}
ll lcm(ll a, ll b){return abs(a) / gcd(a, b) * abs(b);}
ll LASTBIT(ll mask){return (mask) & (-mask);}
int pop_cnt(ull mask){return __builtin_popcountll(mask);}
int ctz(ull mask){return __builtin_ctzll(mask);}
int logOf(ull mask){return 63 - __builtin_clzll(mask);}
mt19937_64 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
// mt19937_64 rng(1);
ll rngesus(ll l, ll r){return l + (ull) rng() % (r - l + 1);}
template <class T1, class T2>
bool maximize(T1 &a, T2 b){
if (a < b) {a = b; return true;}
return false;
}
template <class T1, class T2>
bool minimize(T1 &a, T2 b){
if (a > b) {a = b; return true;}
return false;
}
template <class T>
void printArr(T container, string separator = " ", string finish = "\n", ostream &out = cout){
for(auto item: container) out << item << separator;
out << finish;
}
ll getArea(pair<ll, ll> a, pair<ll, ll> b, pair<ll, ll> c){
return a.first * (b.second - c.second) + b.first * (c.second - a.second) + c.first * (a.second - b.second);
}
struct compareccw{
bool operator () (pair<ll, ll> a, pair<ll, ll> b){
return getArea(a, b, make_pair(0, 0)) > 0;
}
};
pair<ll, ll> get_vector(array<ll, 3> a, array<ll, 3> b){
ll left = a[0], right = b[0];
for(ll &i: a) i *= right;
for(ll &i: b) i *= left;
pair<ll, ll> lmao = {b[1] - a[1], b[2] - a[2]};
ll g = gcd(abs(lmao.first), abs(lmao.second));
if (g != 0){
lmao.first /= g;
lmao.second /= g;
}
return lmao;
}
bool is_in_quadrant(pair<ll, ll> p, int x){
if (x == 0){
return p.first >= 0 && p.second >= 0;
}
else if (x == 1) {
return p.first >= 0 && p.second <= 0;
}
else if (x == 2){
return p.first <= 0 && p.second <= 0;
}
else {
return p.first <= 0 && p.second >= 0;
}
}
multiset<pair<ll, ll>, compareccw> S[4];
bool check_3(){
vector<pair<ll, ll>> a;
for(int x = 0; x < 4; ++x) if (S[x].size()){
a.push_back(*S[x].begin());
a.push_back(*S[x].rbegin());
}
int mask = 0;
for(pair<ll, ll> i: a) for(pair<ll, ll> j: a){
if (i.first * j.first <= 0){
ll sum = i.second * abs(j.first) + j.second * abs(i.first);
if (sum > 0) mask |= 1;
else if (sum < 0) mask |= 2;
}
if (i.second * j.second <= 0){
ll sum = i.first * abs(j.second) + j.first * abs(i.second);
if (sum > 0) mask |= 4;
else if (sum < 0) mask |= 8;
}
}
return ((mask & 3) == 3 || (mask & 12) == 12);
}
void solve(){
array<ll, 3> cake;
for(ll &i: cake)
cin >> i;
int idx = max_element(ALL(cake)) - cake.begin();
swap(cake[0], cake[idx]);
int q; cin >> q;
vector<pair<ll, ll>> dude;
vector<bool> activated;
ll zero_cnt = 0;
map<pair<ll, ll>, ll> mp;
ll pair_cnt = 0;
for(int it = 0; it < q; ++it){
char type; cin >> type;
if (type == 'A'){
array<ll, 3> cur;
for(ll &i: cur) cin >> i;
swap(cur[0], cur[idx]);
pair<ll, ll> vec = get_vector(cake, cur);
dude.push_back(vec);
activated.push_back(1);
if (abs(vec.first) + abs(vec.second) == 0){
zero_cnt++;
}
else{
mp[vec]++;
pair<ll, ll> _vec = make_pair(-vec.first, -vec.second);
pair_cnt += mp[_vec];
for(int x = 0; x < 4; ++x) if (is_in_quadrant(vec, x))
S[x].insert(vec);
}
}
else{
int j; cin >> j;
j--;
activated[j] = 0;
pair<ll, ll> vec = dude[j];
if (abs(vec.first) + abs(vec.second) == 0){
zero_cnt--;
}
else{
mp[vec]--;
pair<ll, ll> _vec = make_pair(-vec.first, -vec.second);
pair_cnt -= mp[_vec];
for(int x = 0; x < 4; ++x) if (is_in_quadrant(vec, x))
S[x].erase(S[x].find(vec));
}
}
if (zero_cnt) cout << 1 << "\n";
else if (pair_cnt) cout << 2 << "\n";
else if (check_3()) cout << 3 << "\n";
else cout << 0 << "\n";
}
}
int main(void){
ios::sync_with_stdio(0);cin.tie(0); cout.tie(0);
clock_t start = clock();
solve();
cerr << "Time elapsed: " << clock() - start << "ms!\n";
return 0;
}