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

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string.h>
#include <vector>

#define FOR(i, a, b) for (lint i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(a) (a).begin(), (a).end()

typedef long long lint;

using namespace std;
lint p = 1e9 + 7;

lint gcd(lint m, lint n) {
  if (n == 0)
    return m;
  else
    return gcd(n, m % n);
}

lint lcm(lint m, lint n) { return m / gcd(m, n) * n; }

int main() {
  lint pow2[200001];
  pow2[0] = 1;
  FOR(i, 1, 200001) { pow2[i] = (pow2[i - 1] * 2) % p; }
  lint N;
  cin >> N;
  map<pair<lint, lint>, lint> m;
  REP(i, N) {
    lint A, B;
    cin >> A >> B;
    if (A == 0 and B == 0) {
      m[make_pair(0, 0)]++;
      continue;
    }
    lint K = gcd(A, B);
    A /= K;
    B /= K;
    if (A < 0) {
      A *= -1;
      B *= -1;
    } else if (A == 0)
      B = -1;
    m[make_pair(A, B)]++;
  }
  vector<pair<lint, lint>> v;
  for (auto e : m) {
    // cerr<<e.first.first<<" "<<e.first.second<<":"<<e.second<<endl;
    if (e.first.first > 0) {
      v.push_back(make_pair(e.second,
                            m[make_pair(e.first.second, e.first.first * -1)]));
    }
  }
  lint ans = 1;
  lint t = N;
  for (auto e : v) {
    if (e.second == 0)
      continue;
    t -= e.first + e.second;
    // cerr<<e.first<<" "<<e.second<<endl;
    lint temp = pow2[e.first] + pow2[e.second] - 1;
    temp += p;
    temp %= p;
    // cerr<<temp<<endl;
    ans *= temp;
    ans %= p;
  }
  lint m0 = m[make_pair(0, 0)];
  t -= m0;
  ans *= pow2[t];
  ans += p - 1;
  ans %= p;
  ans += m0;
  ans %= p;
  cout << ans << endl;
  return 0;
}


Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string.h>
#include <vector>

#define FOR(i, a, b) for (lint i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(a) (a).begin(), (a).end()

typedef long long lint;

using namespace std;
lint p = 1e9 + 7;

lint gcd(lint m, lint n) {
  if (n == 0)
    return m;
  else
    return gcd(n, m % n);
}

lint lcm(lint m, lint n) { return m / gcd(m, n) * n; }

int main() {
  lint pow2[200001];
  pow2[0] = 1;
  FOR(i, 1, 200001) { pow2[i] = (pow2[i - 1] * 2) % p; }
  lint N;
  cin >> N;
  map<pair<lint, lint>, lint> m;
  REP(i, N) {
    lint A, B;
    cin >> A >> B;
    if (A == 0 and B == 0)
      return 1;
    lint K = gcd(A, B);
    A /= K;
    B /= K;
    if (A < 0) {
      A *= -1;
      B *= -1;
    } else if (A == 0)
      B = (B != 0 ? -1 : 0);
    m[make_pair(A, B)]++;
  }
  vector<pair<lint, lint>> v;
  for (auto e : m) {
    // cerr<<e.first.first<<" "<<e.first.second<<":"<<e.second<<endl;
    if (e.first.first > 0) {
      v.push_back(make_pair(e.second,
                            m[make_pair(e.first.second, e.first.first * -1)]));
    }
  }
  lint ans = 1;
  lint t = N;
  for (auto e : v) {
    if (e.second == 0)
      continue;
    t -= e.first + e.second;
    // cerr<<e.first<<" "<<e.second<<endl;
    lint temp = pow2[e.first] + pow2[e.second] - 1;
    temp += p;
    temp %= p;
    // cerr<<temp<<endl;
    ans *= temp;
    ans %= p;
  }
  ans *= pow2[t];
  ans += p - 1;
  ans %= p;
  ans %= p;
  cout << ans << endl;
  return 0;
}