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

// #include "pch.h"
#include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <fstream>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>

typedef long long ll;
typedef std::pair<int, int> Pii;
typedef std::pair<long long, long long> Pll;
typedef std::pair<double, double> Pdd;

#define rip(i, n, s) for (int i = (s); i < (int)(n); i++)
#define all(a) a.begin(), a.end()
#define MM << " " <<

template <typename T> using MaxHeap = std::priority_queue<T>;
template <typename T>
using MinHeap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

template <typename T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

template <typename T> void vdeb(std::vector<T> &da) {
  for (int i = 0; i < da.size(); i++) {
    if (i == da.size() - 1)
      std::cout << da[i];
    else
      std::cout << da[i] << ' ';
  }
  std::cout << std::endl;
}
template <typename T> void vdeb(std::vector<std::vector<T>> &da) {
  for (int i = 0; i < da.size(); i++) {
    std::cout << i << ' ';
    vdeb(da[i]);
  }
  std::cout << std::endl;
}

using namespace std;

long long gcd(ll x, ll y) {
  if (x < y)
    swap(x, y);
  if (y == 0)
    return x;
  while (x % y) {
    long long tmp = y;
    y = x % y;
    x = tmp;
  }
  return y;
}

Pll stand(Pll x) {
  if (x.first == 0 && x.second == 0)
    return {0, 0};
  ll g = gcd(abs(x.first), abs(x.second));
  Pll ret = {x.first / g, x.second / g};
  if (ret.first < 0) {
    ret.first *= -1LL;
    ret.second *= -1LL;
  } else if (ret.first == 0) {
    ret.second = abs(ret.second);
  }
  if (ret.second <= 0) {
    ret = {-ret.second, ret.first};
  }
  return ret;
}

const ll mod = 1000000007;

int main() {
  int n;
  cin >> n;
  vector<Pll> da(n);
  rip(i, n, 0) { cin >> da[i].first >> da[i].second; }
  int ju = 0;
  vector<ll> li(n + 1, 1);
  rip(i, n, 0) { li[i + 1] = li[i] * 2 % mod; }
  map<Pll, Pll> mp;
  rip(i, n, 0) {
    Pll now = stand(da[i]);
    if (mp.count(now))
      mp[now].second;
    else
      mp[now] = {0, 0};
    if ((da[i].first <= 0 && da[i].second < 0) ||
        (da[i].first >= 0 && da[i].second > 0))
      mp[now].first++;
    else
      mp[now].second++;
  }
  ll ans = 1;
  for (auto i : mp) {
    if (i.first.first == 0 && i.first.second == 0) {
      ju += i.second.second;
      continue;
    }
    ll now = li[i.second.first] + li[i.second.second] - 1;
    now = (now + mod) % mod;
    ans *= now;
    ans %= mod;
  }
  ans = (ans + mod - 1 + ju) % mod;
  assert(0 <= ans);
  std::cout << ans << endl;
}

Error: 0

Fixed submission:

// #include "pch.h"
#include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <fstream>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>

typedef long long ll;
typedef std::pair<int, int> Pii;
typedef std::pair<long long, long long> Pll;
typedef std::pair<double, double> Pdd;

#define rip(i, n, s) for (int i = (s); i < (int)(n); i++)
#define all(a) a.begin(), a.end()
#define MM << " " <<

template <typename T> using MaxHeap = std::priority_queue<T>;
template <typename T>
using MinHeap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

template <typename T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

template <typename T> void vdeb(std::vector<T> &da) {
  for (int i = 0; i < da.size(); i++) {
    if (i == da.size() - 1)
      std::cout << da[i];
    else
      std::cout << da[i] << ' ';
  }
  std::cout << std::endl;
}
template <typename T> void vdeb(std::vector<std::vector<T>> &da) {
  for (int i = 0; i < da.size(); i++) {
    std::cout << i << ' ';
    vdeb(da[i]);
  }
  std::cout << std::endl;
}

using namespace std;

long long gcd(ll x, ll y) {
  if (x < y)
    swap(x, y);
  if (y == 0)
    return x;
  while (x % y) {
    long long tmp = y;
    y = x % y;
    x = tmp;
  }
  return y;
}

Pii stand(Pii x) {
  ll g = gcd(abs(x.first), abs(x.second));
  Pii ret = {x.first / g, x.second / g};
  if (ret.first < 0) {
    ret.first *= -1;
    ret.second *= -1;
  } else if (ret.first == 0) {
    ret.second = abs(ret.second);
  }
  if (ret.second <= 0) {
    ret = {-ret.second, ret.first};
  }
  return ret;
}

const ll mod = 1000000007;

int main() {
  int n;
  cin >> n;
  vector<Pll> da(n);
  rip(i, n, 0) { cin >> da[i].first >> da[i].second; }
  vector<ll> li(n + 1, 1);
  rip(i, n, 0) { li[i + 1] = li[i] * 2 % mod; }
  map<Pii, Pii> mp;
  rip(i, n, 0) {
    Pii now = stand(da[i]);
    if (!mp.count(now))
      mp[now] = {0, 0};
    if ((da[i].first <= 0 && da[i].second < 0) ||
        (da[i].first >= 0 && da[i].second > 0))
      mp[now].first++;
    else
      mp[now].second++;
  }
  ll ans = 1;
  for (auto i : mp) {
    if (i.first.first == 0 && i.first.second == 0)
      continue;
    ll now = li[i.second.first] + li[i.second.second] - 1;
    now %= mod;
    ans *= now;
    ans %= mod;
  }
  std::cout << ans - 1 << endl;
}