fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. typedef long long ll;
  5. typedef long double ld;
  6. typedef double db;
  7. typedef string str;
  8.  
  9. typedef pair<int,int> pi;
  10. typedef pair<ll,ll> pl;
  11. typedef pair<db,db> pd;
  12.  
  13. typedef vector<int> vi;
  14. typedef vector<ll> vl;
  15. typedef vector<db> vd;
  16. typedef vector<str> vs;
  17. typedef vector<pi> vpi;
  18. typedef vector<pl> vpl;
  19. typedef vector<pd> vpd;
  20.  
  21. #define mp make_pair
  22. #define f first
  23. #define s second
  24. #define sz(x) (int)(x).size()
  25. #define all(x) begin(x), end(x)
  26. #define rall(x) (x).rbegin(), (x).rend()
  27. #define rsz resize
  28. #define ins insert
  29. #define ft front()
  30. #define bk back()
  31. #define pf push_front
  32. #define pb push_back
  33. #define eb emplace_back
  34. #define lb lower_bound
  35. #define ub upper_bound
  36.  
  37. #define FOR(i,a,b) for (int i = (a); i < (b); ++i)
  38. #define F0R(i,a) FOR(i,0,a)
  39. #define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
  40. #define R0F(i,a) ROF(i,0,a)
  41. #define trav(a,x) for (auto& a: x)
  42.  
  43. const int MOD = 1e9+7; // 998244353;
  44. const int MX = 2e5+5;
  45. const ll INF = 1e18;
  46. const ld PI = acos((ld)-1);
  47. const int xd[4] = {1,0,-1,0}, yd[4] = {0,1,0,-1};
  48. mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count());
  49.  
  50. template<class T> bool ckmin(T& a, const T& b) {
  51. return b < a ? a = b, 1 : 0; }
  52. template<class T> bool ckmax(T& a, const T& b) {
  53. return a < b ? a = b, 1 : 0; }
  54. constexpr int pct(int x) { return __builtin_popcount(x); }
  55. constexpr int bits(int x) { return 31-__builtin_clz(x); } // floor(log2(x))
  56. ll cdiv(ll a, ll b) { return a/b+((a^b)>0&&a%b); } // divide a by b rounded up
  57. ll fdiv(ll a, ll b) { return a/b-((a^b)<0&&a%b); } // divide a by b rounded down
  58. ll half(ll x) { return fdiv(x,2); }
  59.  
  60. template<class T, class U> T fstTrue(T lo, T hi, U f) {
  61. hi ++; assert(lo <= hi); // assuming f is increasing
  62. while (lo < hi) { // find first index such that f is true
  63. T mid = half(lo+hi);
  64. f(mid) ? hi = mid : lo = mid+1;
  65. }
  66. return lo;
  67. }
  68. template<class T, class U> T lstTrue(T lo, T hi, U f) {
  69. lo --; assert(lo <= hi); // assuming f is decreasing
  70. while (lo < hi) { // find first index such that f is true
  71. T mid = half(lo+hi+1);
  72. f(mid) ? lo = mid : hi = mid-1;
  73. }
  74. return lo;
  75. }
  76. template<class T> void remDup(vector<T>& v) {
  77. sort(all(v)); v.erase(unique(all(v)),end(v)); }
  78.  
  79. // INPUT
  80. template<class A> void re(complex<A>& c);
  81. template<class A, class B> void re(pair<A,B>& p);
  82. template<class A> void re(vector<A>& v);
  83. template<class A, size_t SZ> void re(array<A,SZ>& a);
  84.  
  85. template<class T> void re(T& x) { cin >> x; }
  86. void re(db& d) { str t; re(t); d = stod(t); }
  87. void re(ld& d) { str t; re(t); d = stold(t); }
  88. template<class H, class... T> void re(H& h, T&... t) { re(h); re(t...); }
  89.  
  90. template<class A> void re(complex<A>& c) { A a,b; re(a,b); c = {a,b}; }
  91. template<class A, class B> void re(pair<A,B>& p) { re(p.f,p.s); }
  92. template<class A> void re(vector<A>& x) { trav(a,x) re(a); }
  93. template<class A, size_t SZ> void re(array<A,SZ>& x) { trav(a,x) re(a); }
  94.  
  95. // TO_STRING
  96. #define ts to_string
  97. str ts(char c) { return str(1,c); }
  98. str ts(const char* s) { return (str)s; }
  99. str ts(str s) { return s; }
  100. str ts(bool b) {
  101. #ifdef LOCAL
  102. return b ? "true" : "false";
  103. #else
  104. return ts((int)b);
  105. #endif
  106. }
  107. template<class A> str ts(complex<A> c) {
  108. stringstream ss; ss << c; return ss.str(); }
  109. str ts(vector<bool> v) {
  110. str res = "{"; F0R(i,sz(v)) res += char('0'+v[i]);
  111. res += "}"; return res; }
  112. template<size_t SZ> str ts(bitset<SZ> b) {
  113. str res = ""; F0R(i,SZ) res += char('0'+b[i]);
  114. return res; }
  115. template<class A, class B> str ts(pair<A,B> p);
  116. template<class T> str ts(T v) { // containers with begin(), end()
  117. #ifdef LOCAL
  118. bool fst = 1; str res = "{";
  119. for (const auto& x: v) {
  120. if (!fst) res += ", ";
  121. fst = 0; res += ts(x);
  122. }
  123. res += "}"; return res;
  124. #else
  125. bool fst = 1; str res = "";
  126. for (const auto& x: v) {
  127. if (!fst) res += " ";
  128. fst = 0; res += ts(x);
  129. }
  130. return res;
  131.  
  132. #endif
  133. }
  134. template<class A, class B> str ts(pair<A,B> p) {
  135. #ifdef LOCAL
  136. return "("+ts(p.f)+", "+ts(p.s)+")";
  137. #else
  138. return ts(p.f)+" "+ts(p.s);
  139. #endif
  140. }
  141.  
  142. // OUTPUT
  143. template<class A> void pr(A x) { cout << ts(x); }
  144. template<class H, class... T> void pr(const H& h, const T&... t) {
  145. pr(h); pr(t...); }
  146. void ps() { pr("\n"); } // print w/ spaces
  147. template<class H, class... T> void ps(const H& h, const T&... t) {
  148. pr(h); if (sizeof...(t)) pr(" "); ps(t...); }
  149.  
  150. // DEBUG
  151. void DBG() { cerr << "]" << endl; }
  152. template<class H, class... T> void DBG(H h, T... t) {
  153. cerr << ts(h); if (sizeof...(t)) cerr << ", ";
  154. DBG(t...); }
  155. #ifdef LOCAL // compile with -DLOCAL
  156. #define dbg(...) cerr << "LINE(" << __LINE__ << ") -> [" << #__VA_ARGS__ << "]: [", DBG(__VA_ARGS__)
  157. #else
  158. #define dbg(...) 0
  159. #endif
  160.  
  161. // FILE I/O
  162. void setIn(str s) { freopen(s.c_str(),"r",stdin); }
  163. void setOut(str s) { freopen(s.c_str(),"w",stdout); }
  164. void unsyncIO() { ios_base::sync_with_stdio(0); cin.tie(0); }
  165. void setIO(str s = "") {
  166. unsyncIO();
  167. // cin.exceptions(cin.failbit);
  168. // throws exception when do smth illegal
  169. // ex. try to read letter into int
  170. if (sz(s)) { setIn(s+".in"), setOut(s+".out"); } // for USACO
  171. }
  172.  
  173. typedef pl P;
  174.  
  175. int sgn(ll x) {
  176. if (x > 0) return 1;
  177. if (x < 0) return -1;
  178. return 0;
  179. }
  180.  
  181. __int128 cross(P a, P b) {
  182. return (__int128)a.f*b.s-(__int128)a.s*b.f;
  183. }
  184.  
  185. /**
  186.  * Description: Sorts points in ccw order about origin in the same way as
  187.   * \texttt{atan2}, which returns real in $(-\pi,\pi]$ so points on
  188.   * negative $x$-axis come last.
  189.  * Verification: https://c...content-available-to-author-only...s.com/contest/1284/submission/68175790
  190.   * https://c...content-available-to-author-only...s.com/contest/1284/submission/68207607
  191.   * (don't use atan2, weird stuff happens!)
  192.  */
  193.  
  194. int half(P x) { return x.s != 0 ? sgn(x.s) : -sgn(x.f); } // -1 if lower half, 0 if origin, 1 if upper half
  195. bool angleCmp(P a, P b) {
  196. int A = half(a), B = half(b);
  197. return A == B ? cross(a,b) > 0 : A < B; }
  198.  
  199. /** Usage:
  200.   * vP v;
  201.   * sort(all(v),[](P a, P b) { return
  202.   atan2(a.s,a.f) < atan2(b.s,b.f); });
  203.   * sort(all(v),angleCmp); // should give same result
  204. */
  205.  
  206. typedef array<ll,3> T;
  207.  
  208. T a;
  209. int eq = 0, neg = 0;
  210. vpl cat;
  211.  
  212. struct cmp {
  213. bool operator()(const pl& a, const pl& b) const {
  214. return angleCmp(a,b);
  215. };
  216. };
  217.  
  218. map<pl,int,cmp> m;
  219.  
  220. T operator*(T a, ll b) {
  221. trav(t,a) t *= b;
  222. return a;
  223. }
  224. T operator-(T a, T b) {
  225. F0R(i,3) a[i] -= b[i];
  226. return a;
  227. }
  228.  
  229. ll sum(T t) { return t[0]+t[1]+t[2]; }
  230. // T nor(T a) {
  231. // int g = __gcd(abs(a[0]),__gcd(abs(a[1]),abs(a[2])));
  232. // F0R(i,3) a[i] /= g;
  233. // return a;
  234. // }
  235.  
  236. ll dot(T a, T b) {
  237. ll res = 0;
  238. F0R(i,3) res += a[i]*b[i];
  239. return res;
  240. }
  241.  
  242. pl lst;
  243.  
  244. const pl ID = mp(0LL,0LL);
  245.  
  246. void ad(pl p, int x) {
  247. if (p == ID) {
  248. eq += x;
  249. return;
  250. }
  251. vpl cand = {lst,p};
  252. if (x == 1) {
  253. if (!m.count(p) && m.count({-p.f,-p.s})) neg ++;
  254. m[p] ++;
  255. } else {
  256. if (m[p] == 1 && m.count({-p.f,-p.s})) neg --;
  257. auto it = m.find(p);
  258. if (it == begin(m)) it = end(m);
  259. it --; cand.pb(it->f);
  260. m[p] --; if (!m[p]) m.erase(p);
  261. }
  262. lst = {0,0};
  263. auto bad = [&](pl a, pl b) {
  264. return a == b || cross(a,b) < 0;
  265. };
  266. trav(t,cand) {
  267. auto it = m.find(t); if (it == end(m)) continue;
  268. auto IT = next(it); if (IT == end(m)) IT = begin(m);
  269. if (bad(t,IT->f)) {
  270. // assert(lst == mp(0LL,0LL));
  271. lst = t;
  272. }
  273. }
  274. }
  275.  
  276.  
  277. int answer() {
  278. if (eq) return 1;
  279. if (neg) return 2;
  280. if (sz(m)) { if (lst == ID) return 3; }
  281. return 0;
  282. }
  283.  
  284. int main() {
  285. setIO(); re(a);
  286. int N; re(N);
  287. F0R(i,N) {
  288. char c; re(c);
  289. if (c == 'A') {
  290. T t; re(t);
  291. t = t*sum(a)-a*sum(t); assert(sum(t) == 0);
  292. pl p = {dot(t,{1,-1,0}),dot(t,{1,1,-2})};
  293. ll g = __gcd(abs(p.f),abs(p.s));
  294. if (p.f || p.s) p.f /= g, p.s /= g;
  295. cat.pb(p); ad(cat.bk,1);
  296. } else {
  297. int r; re(r); r --;
  298. ad(cat[r],-1);
  299. }
  300. ps(answer());
  301. }
  302. // you should actually read the stuff at the bottom
  303. }
  304.  
  305. /* stuff you should look for
  306. * int overflow, array bounds
  307. * special cases (n=1?)
  308. * do smth instead of nothing and stay organized
  309. * WRITE STUFF DOWN
  310. */
  311.  
Runtime error #stdin #stdout 0s 4248KB
stdin
Standard input is empty
stdout
Standard output is empty