Problem p02679 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const ll mod = 1000000007;
// const ll mod = 998244353;
const int inf = 1e9 + 10;
const ll INF = 1e18;
const ld EPS = 1e-10;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

struct Point {
  __int128_t x, y;
};

__int128_t cross(Point p1, Point p2) { return p1.x * p2.y - p2.x * p1.y; }

bool cmp(Point p1, Point p2) { return cross(p1, p2) > 0; }

ll pow2[200200];

void init() {
  pow2[0] = 1;
  rep(i, 200200 - 1) { pow2[i + 1] = pow2[i] * 2 % mod; }
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(25);

  init();

  ll n;
  cin >> n;
  vector<Point> p[2];
  ll ans = 0;
  rep(i, n) {
    Point a;
    ll x, y;
    cin >> x >> y;
    a = {x, y};
    if (a.x == 0 && a.y == 0) {
      ans++;
      continue;
    }
    if (a.x > 0 && a.y >= 0)
      p[0].push_back(a);
    else if (a.x <= 0 && a.y > 0) {
      a.x *= -1;
      swap(a.x, a.y);
      p[1].push_back(a);
    } else if (a.x < 0 && a.y <= 0) {
      a.x *= -1;
      a.y *= -1;
      p[0].push_back(a);
    } else {
      a.y *= -1;
      swap(a.x, a.y);
      p[1].push_back(a);
    }
  }
  rep(i, 2) sort(p[i].begin(), p[i].end(), cmp);
  vector<int> siz(2);
  rep(i, 2) siz[i] = p[i].size();
  vector<int> idx(2, 0);
  ll res = 1;
  vector<int> cnt(2, 1);
  while (idx[0] < siz[0] && idx[1] < siz[1]) {
    rep(i, 2) {
      while (idx[i] + 1 < siz[i] &&
             cross(p[i][idx[i]], p[i][idx[i] + 1]) == 0) {
        cnt[i]++;
        idx[i]++;
      }
    }
    if (cross(p[0][idx[0]], p[1][idx[1]]) == 0) {
      res = res * ((pow2[cnt[0]] + pow2[cnt[1]] - 1) % mod) % mod;
      idx[0]++, idx[1]++;
      cnt[0] = 1, cnt[1] = 1;
    } else if (cross(p[0][idx[0]], p[1][idx[1]]) > 0) {
      res = res * pow2[cnt[0]] % mod;
      idx[0]++;
      cnt[0] = 1;
    } else {
      res = res * pow2[cnt[1]] % mod;
      idx[1]++;
      cnt[1] = 1;
    }
  }
  rep(i, 2) {
    while (idx[i] < siz[i]) {
      res = res * 2 % mod;
      idx[i]++;
    }
  }
  res = (res - 1 + mod) % mod;
  ans = (ans + res) % mod;
  cout << ans << '\\n';

  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const ll mod = 1000000007;
// const ll mod = 998244353;
const int inf = 1e9 + 10;
const ld INF = 1e18;
const ld EPS = 1e-10;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

struct Point {
  ld x, y;

  Point(ld x = 0, ld y = 0) : x(x), y(y) {}

  Point operator+(Point &p) { return Point(x + p.x, y + p.y); }

  Point operator-(Point &p) { return Point(x - p.x, y - p.y); }

  Point operator*(ld k) { return Point(x * k, y * k); }

  Point operator/(ld k) { return Point(x / k, y / k); }

  bool operator<(const Point &p) const { return x != p.x ? x < p.x : y < p.y; }

  bool operator==(const Point &p) const {
    return fabs(x - p.x) < EPS && fabs(y - p.y) < EPS;
  }
};

ld norm(Point p) { return p.x * p.x + p.y * p.y; }

ld dist(Point p) { return sqrt(norm(p)); }

ld dot(Point p1, Point p2) { return p1.x * p2.x + p1.y * p2.y; }

ld cross(Point p1, Point p2) { return p1.x * p2.y - p1.y * p2.x; }

Point rotate(Point p, ld theta) {
  return Point(p.x * cos(theta) - p.y * sin(theta),
               p.x * sin(theta) + p.y * cos(theta));
}

int ccw(Point p0, Point p1, Point p2) {
  Point v1 = p1 - p0, v2 = p2 - p0;
  if (cross(v1, v2) > 0)
    return 1;
  else if (cross(v1, v2) < 0)
    return -1;
  else if (dot(v1, v2) < 0)
    return 2;
  else if (norm(v1) < norm(v2))
    return -2;
  else
    return 0;
}

bool intersect(Point p1, Point p2, Point p3, Point p4) {
  return (ccw(p1, p2, p3) * ccw(p1, p2, p4) <= 0 &&
          ccw(p3, p4, p1) * ccw(p3, p4, p2) <= 0);
}

// 直線p2-p1と点p3の距離
ld getDistanceLP(Point p1, Point p2, Point p3) {
  return fabs(cross(p2 - p1, p3 - p1) / dist(p2 - p1));
}

// 線分s(p2-p1)と点p3の距離
ld getDistanceSP(Point p1, Point p2, Point p3) {
  if (dot(p2 - p1, p3 - p1) < 0)
    return dist(p3 - p1);
  else if (dot(p1 - p2, p3 - p2) < 0)
    return dist(p3 - p2);
  else
    return getDistanceLP(p1, p2, p3);
}

// 線分s1(p2-p1)と線分s2(p4-p3)の距離
ld getDistanceTS(Point p1, Point p2, Point p3, Point p4) {
  if (intersect(p1, p2, p3, p4))
    return 0;
  ld ans = INF;
  ans = min(ans, getDistanceSP(p1, p2, p3));
  ans = min(ans, getDistanceSP(p1, p2, p4));
  ans = min(ans, getDistanceSP(p3, p4, p1));
  ans = min(ans, getDistanceSP(p3, p4, p2));
  return ans;
}

vector<Point> convex_hull(vector<Point> &ps, int n) {
  sort(ps.begin(), ps.end());
  int k = 0;
  vector<Point> qs(2 * n);
  rep(i, n) {
    while (k > 1 && cross(qs[k - 1] - qs[k - 2], ps[i] - qs[k - 1]) <= 0)
      k--;
    qs[k++] = ps[i];
  }
  for (int i = n - 2, t = k; i >= 0; i--) {
    while (k > t && (cross(qs[k - 1] - qs[k - 2], ps[i] - qs[k - 1]) <= 0))
      k--;
    qs[k++] = ps[i];
  }
  qs.resize(k - 1);
  return qs;
}

// 円
struct Circle {
  Point p;
  ld r;

  Circle() {}
  Circle(Point p, ld r) : p(p), r(r) {}
};

// ２円の交点
vector<Point> getIntersections(Circle c1, Circle c2) {
  ld d = dist(c2.p - c1.p);
  ld rc = (c1.r * c1.r + d * d - c2.r * c2.r) / (2 * d);
  ld rs = sqrt(c1.r * c1.r - rc * rc);
  Point e1 = (c2.p - c1.p) / d;
  Point e2 = rotate(e1, M_PI / 2) * rs;
  Point e3 = rotate(e1, -M_PI / 2) * rs;
  e1 = e1 * rc;
  Point a = c1.p + e1 + e2;
  Point b = c1.p + e1 + e3;
  return {a, b};
}

// 座標圧縮
struct Compress {
  vector<ll> xc;

  Compress() {}

  void add(vector<ll> v) {
    for (ll x : v)
      xc.push_back(x);
  }

  void add(ll x) { xc.push_back(x); }

  void build() {
    sort(xc.begin(), xc.end());
    xc.erase(unique(xc.begin(), xc.end()), xc.end());
  }

  ll get(ll &x) { return lower_bound(xc.begin(), xc.end(), x) - xc.begin(); }

  const ll &operator[](int k) const { return xc[k]; }

  ll size() { return xc.size(); }
};

bool cmp(Point p1, Point p2) { return cross(p1, p2) >= 0; }

ll pow2[200200];

void init() {
  pow2[0] = 1;
  rep(i, 200200 - 1) { pow2[i + 1] = pow2[i] * 2 % mod; }
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(50);

  init();

  ll n;
  cin >> n;
  vector<Point> p[2];
  ll ans = 0;
  rep(i, n) {
    Point a;
    cin >> a.x >> a.y;
    if (a.x == 0 && a.y == 0) {
      ans++;
      continue;
    }
    if (a.x > 0 && a.y >= 0)
      p[0].push_back(a);
    else if (a.x <= 0 && a.y > 0) {
      a.x *= -1;
      swap(a.x, a.y);
      p[1].push_back(a);
    } else if (a.x < 0 && a.y <= 0) {
      a = a * (-1);
      p[0].push_back(a);
    } else {
      a = a * (-1);
      a.x *= -1;
      swap(a.x, a.y);
      p[1].push_back(a);
    }
  }
  rep(i, 2) sort(p[i].begin(), p[i].end(), cmp);
  vector<ll> siz(2);
  rep(i, 2) siz[i] = p[i].size();
  vector<ll> idx(2, 0);
  ll res = 1;
  vector<ll> cnt(2, 1);
  while (idx[0] < siz[0] && idx[1] < siz[1]) {
    rep(i, 2) {
      while (idx[i] + 1 < siz[i] &&
             equals(cross(p[i][idx[i]], p[i][idx[i] + 1]), 0)) {
        cnt[i]++;
        idx[i]++;
      }
    }
    if (equals(cross(p[0][idx[0]], p[1][idx[1]]), 0)) {
      res = (pow2[cnt[0]] + pow2[cnt[1]] - 1) % mod * res % mod;
      idx[0]++, idx[1]++;
      cnt[0] = 1, cnt[1] = 1;
    } else if (cross(p[0][idx[0]], p[1][idx[1]]) > 0) {
      res = res * pow2[cnt[0]] % mod;
      idx[0]++;
      cnt[0] = 1;
    } else {
      res = res * pow2[cnt[1]] % mod;
      idx[1]++;
      cnt[1] = 1;
    }
  }
  rep(i, 2) { res = res * pow2[siz[i] - idx[i]] % mod; }
  res = (res - 1 + mod) % mod;
  ans = (ans + res) % mod;
  cout << ans << '\\n';

  return 0;
}