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

#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define pll pair<ll, ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define ios ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define lb(c, x) distance(c.begin(), lower_bound(all(c), x))
#define ub(c, x) distance(c.begin(), upper_bound(all(c), x))

using namespace std;

template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

const ll mod = 1e9 + 7;

ll gcd(ll a, ll b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}

int main() {
  ll n;
  cin >> n;
  // vector<ll> a(n),b(n);
  vector<ll> p(200001);
  ll v = 1;
  rep(i, 200001) {
    p[i] = v;
    v *= 2;
    v %= mod;
  }
  map<pll, ll> m;
  map<pll, bool> s;
  rep(i, n) {
    ll p, q;
    cin >> p >> q;
    if (p == 0 && q == 0) {
      m[make_pair(0, 0)]++;
      continue;
    }
    if (p == 0 && q != 0) {
      m[make_pair(0, 1)]++;
      continue;
    }
    if (p != 0 && q == 0) {
      m[make_pair(1, 0)]++;
      continue;
    }
    ll r = gcd(p, q);
    p /= r;
    q /= r;
    // a[i]=p;
    // b[i]=q;
    m[make_pair(p, q)]++;
  }
  ll ans = 1;
  for (auto x : m) {
    // cout << x.fi.fi << " " << x.fi.se << endl;
    if (x.fi.fi == 0 && x.fi.se == 0) {
      continue;
    }
    if (s.count(make_pair(x.fi.fi, x.fi.se))) {
      continue;
    }
    ll sum1 = 0;
    if (m.count(make_pair(-x.fi.se, x.fi.fi))) {
      sum1 += m[make_pair(-x.fi.se, x.fi.fi)];
      s[make_pair(-x.fi.se, x.fi.fi)] = true;
    }
    if (m.count(make_pair(x.fi.se, -x.fi.fi))) {
      sum1 += m[make_pair(x.fi.se, -x.fi.fi)];
      s[make_pair(x.fi.se, -x.fi.fi)] = true;
    }
    ll sum2 = 0;
    if (m.count(make_pair(x.fi.fi, x.fi.se))) {
      sum2 += m[make_pair(x.fi.fi, x.fi.se)];
      s[make_pair(x.fi.fi, x.fi.se)] = true;
    }
    if (m.count(make_pair(-x.fi.fi, -x.fi.se))) {
      sum2 += m[make_pair(-x.fi.fi, -x.fi.se)];
      s[make_pair(-x.fi.fi, -x.fi.se)] = true;
    }

    ans *= (p[sum1] + p[sum2] - 1) % mod;
    ans %= mod;
  }
  ans += m[make_pair(0, 0)];
  cout << (ans + mod - 1) % mod << endl;
  return 0;
}


Error: 0

Fixed submission:

#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define pll pair<ll, ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define ios ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define lb(c, x) distance(c.begin(), lower_bound(all(c), x))
#define ub(c, x) distance(c.begin(), upper_bound(all(c), x))

using namespace std;

template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

const ll mod = 1e9 + 7;

ll gcd(ll a, ll b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}

int main() {
  ll n;
  cin >> n;
  vector<ll> a(n), b(n);
  vector<ll> p(200001);
  ll v = 1;
  rep(i, 200001) {
    p[i] = v;
    v *= 2;
    v %= mod;
  }
  map<pll, ll> m;
  map<pll, bool> s;
  rep(i, n) {
    ll p, q;
    cin >> p >> q;
    ll r = gcd(p, q);
    p /= r;
    q /= r;
    a[i] = p;
    b[i] = q;
    m[make_pair(p, q)]++;
  }
  ll ans = 1;
  for (auto x : m) {
    // cout << x.fi.fi << " " << x.fi.se << endl;
    if (x.fi.fi == 0 && x.fi.se == 0) {
      continue;
    }
    if (s.count(make_pair(x.fi.fi, x.fi.se))) {
      continue;
    }
    ll sum1 = 0;
    if (m.count(make_pair(-x.fi.se, x.fi.fi))) {
      sum1 += m[make_pair(-x.fi.se, x.fi.fi)];
    }
    if (m.count(make_pair(x.fi.se, -x.fi.fi))) {
      sum1 += m[make_pair(x.fi.se, -x.fi.fi)];
    }
    ll sum2 = 0;
    if (m.count(make_pair(x.fi.fi, x.fi.se))) {
      sum2 += m[make_pair(x.fi.fi, x.fi.se)];
    }
    if (m.count(make_pair(-x.fi.fi, -x.fi.se))) {
      sum2 += m[make_pair(-x.fi.fi, -x.fi.se)];
    }
    s[make_pair(-x.fi.se, x.fi.fi)] = true;
    s[make_pair(x.fi.se, -x.fi.fi)] = true;
    s[make_pair(x.fi.fi, x.fi.se)] = true;
    s[make_pair(-x.fi.fi, -x.fi.se)] = true;
    ans *= (p[sum1] + p[sum2] - 1) % mod;
  }
  ans += m[make_pair(0, 0)];
  cout << (ans + mod - 1) % mod << endl;
  return 0;
}