Submission #261666

# Submission time Handle Problem Language Result Execution time Memory
261666 2020-08-12T00:12:33 Z rama_pang Mixture (BOI20_mixture) C++14
100 / 100
437 ms 17432 KB
#include <bits/stdc++.h>
using namespace std;

class Rational { // a / b
 public:
  __int128_t a, b;
  void Normalize() {
    __int128_t g = __gcd(max(a, -a), max(b, -b));
    a /= g, b /= g;
    if (b < 0) a *= -1, b *= -1;
  }

  Rational() : a(0), b(1) {}
  Rational(__int128_t a) : a(a), b(1) {}
  Rational(__int128_t a, __int128_t b) : a(a), b(b) {}
  
  friend Rational operator + (const Rational &a, const Rational &b) {
    return Rational(a.a * b.b + a.b * b.a, a.b * b.b);
  }

  friend Rational operator - (const Rational &a, const Rational &b) {
    return Rational(a.a * b.b - a.b * b.a, a.b * b.b);
  }

  friend Rational operator * (const Rational &a, const Rational &b) {
    return Rational(a.a * b.a, a.b * b.b);
  }

  friend Rational operator / (const Rational &a, const Rational &b) {
    return Rational(a.a * b.b, a.b * b.a);
  }

  friend bool operator == (const Rational &a, const Rational &b) {
    return a.a == b.a && a.b == b.b;
  }

  friend bool operator != (const Rational &a, const Rational &b) {
    return a.a != b.a || a.b != b.b;
  }

  friend bool operator < (const Rational &a, const Rational &b) {
    return a.a * b.b < a.b * b.a;
  }

  friend bool operator > (const Rational &a, const Rational &b) {
    return a.a * b.b > a.b * b.a;
  }
};

using Point = pair<Rational, Rational>;

Point operator - (const Point &a, const Point &b) {
  return Point(a.first - b.first, a.second - b.second);
}

Point operator * (const Point &a, const int &b) {
  return Point(a.first * b, a.second * b);
}

int Half(Point p) { // upper half or lower half in xy coordinate
  if (p.second != 0) {
    return p.second > 0 ? 1 : -1;
  } else if (p.first != 0) {
    return p.first > 0 ? 1 : -1;
  } else {
    return 0;
  }
}

Rational Cross(Point a, Point b) {
  return (a.first * b.second) - (a.second * b.first);
}

bool AngleCmp(Point a, Point b) {
  int A = Half(a), B = Half(b);
  return A == B ? (Cross(a, b) > 0) : (A > B);
}

struct points_cmp {
  const bool operator() (Point a, Point b) const {
    return AngleCmp(a, b);
  }
};

vector<Point> A;
map<Point, int, points_cmp> points;

int origin = 0;
int inverse = 0;
int gap = 1;

int Query() {
  if (origin) {
    return 1;
  } else if (inverse) {
    return 2;
  } else if (points.size() >= 3 && gap == 0) {
    return 3;
  } else {
    return 0;
  }
}

bool HasGap(Point a, Point b) { // angle between a and b > pi radians
  return a == b || Cross(a, b) < 0;
}

void Insert(Point p) {
  if (p == Point(0, 0)) {
    origin++;
    return;
  }
  if (points.count(p)) {
    points[p]++;
    return;
  }
  points[p] = 1;
  auto it = points.find(p);
  if (points.count(p * -1)) {
    inverse++;
  }
  auto nxt = next(it); if (nxt == end(points)) nxt = begin(points);
  auto prv = it; if (prv == begin(points)) prv = end(points); prv--;
  if (HasGap(prv->first, nxt->first) && !HasGap(prv->first, it->first) && !HasGap(it->first, nxt->first)) {
    gap = 0;
  }
}

void Erase(Point p) {
  if (p == Point(0, 0)) {
    origin--;
    return;
  }
  if (points[p] > 1) {
    points[p]--;
    return;
  }
  auto it = points.find(p);
  if (points.count(p * -1)) {
    inverse--;
  }
  auto nxt = next(it); if (nxt == end(points)) nxt = begin(points);
  auto prv = it; if (prv == begin(points)) prv = end(points); prv--;
  if (HasGap(prv->first, nxt->first)) {
    gap = 1;
  }
  points.erase(p);
}

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

  array<long long, 3> S;
  cin >> S[0] >> S[1] >> S[2];

  int Q;
  cin >> Q;
  while (Q--) {
    string t;
    cin >> t;
    if (t == "A") {
      auto Sum = [&](const array<long long, 3> &x) {
        return x[0] + x[1] + x[2];
      };
      array<long long, 3> T;
      cin >> T[0] >> T[1] >> T[2];
      long long sumT = Sum(T);
      for (int i = 0; i < 3; i++) {
        T[i] = 1ll * T[i] * Sum(S) - S[i] * sumT;
      }
      A.emplace_back(Point(Rational(T[0], sumT), Rational(T[1], sumT)));
      A.back().first.Normalize(), A.back().second.Normalize();
      Insert(A.back());
    } else if (t == "R") {
      int r;
      cin >> r;
      Erase(A[--r]);
    }
    cout << Query() << "\n";
  }
  return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 392 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 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 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 392 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 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 384 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 1 ms 384 KB Output is correct
29 Correct 1 ms 384 KB Output is correct
30 Correct 1 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 1 ms 384 KB Output is correct
34 Correct 2 ms 384 KB Output is correct
35 Correct 1 ms 384 KB Output is correct
36 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 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 392 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 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 384 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 1 ms 384 KB Output is correct
29 Correct 1 ms 384 KB Output is correct
30 Correct 1 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 1 ms 384 KB Output is correct
34 Correct 2 ms 384 KB Output is correct
35 Correct 1 ms 384 KB Output is correct
36 Correct 1 ms 384 KB Output is correct
37 Correct 2 ms 384 KB Output is correct
38 Correct 2 ms 384 KB Output is correct
39 Correct 2 ms 512 KB Output is correct
40 Correct 3 ms 512 KB Output is correct
41 Correct 2 ms 512 KB Output is correct
42 Correct 2 ms 512 KB Output is correct
43 Correct 3 ms 512 KB Output is correct
44 Correct 4 ms 512 KB Output is correct
45 Correct 3 ms 512 KB Output is correct
46 Correct 9 ms 768 KB Output is correct
47 Correct 9 ms 896 KB Output is correct
48 Correct 4 ms 640 KB Output is correct
49 Correct 5 ms 640 KB Output is correct
50 Correct 5 ms 640 KB Output is correct
51 Correct 13 ms 892 KB Output is correct
52 Correct 7 ms 1168 KB Output is correct
53 Correct 10 ms 1276 KB Output is correct
54 Correct 11 ms 1148 KB Output is correct
55 Correct 4 ms 768 KB Output is correct
56 Correct 4 ms 768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 392 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 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 384 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 1 ms 384 KB Output is correct
29 Correct 1 ms 384 KB Output is correct
30 Correct 1 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 1 ms 384 KB Output is correct
34 Correct 2 ms 384 KB Output is correct
35 Correct 1 ms 384 KB Output is correct
36 Correct 1 ms 384 KB Output is correct
37 Correct 2 ms 384 KB Output is correct
38 Correct 2 ms 384 KB Output is correct
39 Correct 2 ms 512 KB Output is correct
40 Correct 3 ms 512 KB Output is correct
41 Correct 2 ms 512 KB Output is correct
42 Correct 2 ms 512 KB Output is correct
43 Correct 3 ms 512 KB Output is correct
44 Correct 4 ms 512 KB Output is correct
45 Correct 3 ms 512 KB Output is correct
46 Correct 9 ms 768 KB Output is correct
47 Correct 9 ms 896 KB Output is correct
48 Correct 4 ms 640 KB Output is correct
49 Correct 5 ms 640 KB Output is correct
50 Correct 5 ms 640 KB Output is correct
51 Correct 13 ms 892 KB Output is correct
52 Correct 7 ms 1168 KB Output is correct
53 Correct 10 ms 1276 KB Output is correct
54 Correct 11 ms 1148 KB Output is correct
55 Correct 4 ms 768 KB Output is correct
56 Correct 4 ms 768 KB Output is correct
57 Correct 7 ms 1152 KB Output is correct
58 Correct 25 ms 1232 KB Output is correct
59 Correct 20 ms 1232 KB Output is correct
60 Correct 16 ms 1216 KB Output is correct
61 Correct 27 ms 2940 KB Output is correct
62 Correct 25 ms 3060 KB Output is correct
63 Correct 393 ms 15324 KB Output is correct
64 Correct 344 ms 15476 KB Output is correct
65 Correct 333 ms 8376 KB Output is correct
66 Correct 372 ms 8536 KB Output is correct
67 Correct 1 ms 384 KB Output is correct
68 Correct 0 ms 384 KB Output is correct
69 Correct 437 ms 17432 KB Output is correct
70 Correct 361 ms 16476 KB Output is correct
71 Correct 358 ms 16480 KB Output is correct
72 Correct 322 ms 14556 KB Output is correct
73 Correct 356 ms 15456 KB Output is correct