#define wiwihorz
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma loop-opt(on)
#define rep(i, a, b) for(int i = a; i <= b; i++)
#define rrep(i, a, b) for(int i = b; i >= a; i--)
#define all(x) x.begin(), x.end()
#define ceil(a, b)
using namespace std;
#define INF 1000000000000000000
#define lld long double
#define int long long int
#define pii pair<int, int>
#define random mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count())
#ifdef wiwihorz
#define print(a...) kout("[" + string(#a) + "] = ", a)
void vprint(auto L, auto R) { while(L < R) cerr << *L << " \n"[next(L) == R], ++L;}
void kout() { cerr << endl; }
template<class T1, class ... T2> void kout(T1 a, T2 ... e) { cerr << a << " ", kout(e...); }
#else
#define print(...)
#define vprint(...)
#endif
namespace solver {
int n, s, p, g, cnt;
set<int> a;
set<pii> b;
vector<int> S, P, G, vis;
void init_(int _n, int _s, int _p, int _g) {
n = _n, s = _s, p = _p, g = _g;
int gcd = __gcd(s, __gcd(p, g));
s /= gcd, p /= gcd, g /= gcd, cnt = 0;
S.assign(n + 1, 0);
P.assign(n + 1, 0);
G.assign(n + 1, 0);
vis.assign(n + 1, 0);
a.clear(), b.clear();
}
bool check(int i, int j) {
int d = S[i] * P[j] - S[j] * P[i];
int dx = s * P[j] - S[j] * p;
int dy = S[i] * p - s * P[i];
// if(d) print(S[i], S[j], s, P[i], P[j], p), print()
if(!d || G[i] * dx + G[j] * dy != g * d) return 0;
return 1;
}
int add(int x, int y, int z) {
int gcd = __gcd(x, __gcd(z, y));
x /= gcd, y /= gcd, z /= gcd;
++cnt;
S[cnt] = x, P[cnt] = y, G[cnt] = z;
if(x == s && p == y && g == z) a.insert(cnt);
else {
rep(i, 1, cnt - 1) if(!vis[i]) {
if(check(i, cnt)) b.insert({i, cnt});
}
}
return a.size() ? 1 : 2 * bool(b.size());
}
int remove(int id) {
vis[id] = 1;
if(a.find(id) != a.end()) a.erase(a.find(id));
rep(i, 1, id - 1) if(b.find({i, id}) != b.end())
b.erase(b.find({i, id}));
rep(i, id + 1, cnt) if(b.find({id, i}) != b.end())
b.erase(b.find({id, i}));
return a.size() ? 1 : 2 * bool(b.size());
}
};
using namespace solver;
signed main() {
ios::sync_with_stdio(false), cin.tie(0);
int s, p, g, n;
cin >> s >> p >> g >> n;
init_(n, s, p, g);
rep(i, 1, n) {
char c; cin >> c;
if(c == 'A') {
int x, y, z;
cin >> x >> y >> z;
cout << add(x, y, z) << "\n";
}
else {
int x; cin >> x;
cout << remove(x) << "\n";
}
}
return 0;
}
Compilation message
Mixture.cpp:4: warning: ignoring '#pragma loop ' [-Wunknown-pragmas]
4 | #pragma loop-opt(on)
|
Mixture.cpp:21:13: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
21 | void vprint(auto L, auto R) { while(L < R) cerr << *L << " \n"[next(L) == R], ++L;}
| ^~~~
Mixture.cpp:21:21: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
21 | void vprint(auto L, auto R) { while(L < R) cerr << *L << " \n"[next(L) == R], ++L;}
| ^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |