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

#include <algorithm>
#include <bitset>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;
typedef long long ll;

const ll MOD = 1000000007;

int main() {
  int N;
  cin >> N;

  vector<ll> p2(N + 1, 0);
  p2[0] = 1;
  for (int i = 1; i < N + 1; i++) {
    p2[i] = p2[i - 1] * 2 % MOD;
  }

  map<pair<ll, ll>, ll> m;
  for (int i = 0; i < N; i++) {
    ll a, b;
    cin >> a >> b;
    if (a == 0 && b == 0) {
      m[make_pair<ll, ll>(0, 0)]++;
      continue;
    }
    if (a == 0) {
      m[make_pair<ll, ll>(0, 1)]++;
      continue;
    }
    if (b == 0) {
      m[make_pair<ll, ll>(1, 0)]++;
      continue;
    }

    ll ta = abs(a), tb = abs(b);
    while (ta != 0) {
      tb %= ta;
      swap(ta, tb);
    }
    a /= tb;
    b /= tb;
    if (a < 0) {
      a *= -1;
      b *= -1;
    }
    // cout << "#" << a <<" "<< b << endl;
    m[make_pair(a, b)]++;
  }

  // for(auto mi:m) cout << "##" << mi.first.first << "," << mi.first.second <<
  // " " << mi.second << endl;

  ll ans = 1;
  for (auto &mi : m) {
    if (mi.first.first == 0 && mi.first.second == 0)
      continue;
    pair<ll, ll> tmp;
    if (mi.first.second > 0) {
      tmp.first = mi.first.second;
      tmp.second = -mi.first.first;
    } else {
      tmp.first = -mi.first.second;
      tmp.second = mi.first.first;
    }

    // cout << "**" << mi.first.first << "," << mi.first.second << " " <<
    // tmp.first << "," << tmp.second << endl;

    ll ansi = 0;
    ansi += p2[m[tmp]];
    ansi += p2[mi.second];
    ans *= ansi - 1;
    ans %= MOD;
    m[tmp] = 0;
    mi.second = 0;
  }

  cout << ((ans - 1 + m[make_pair<ll, ll>(0, 0)]) % MOD + MOD) % MOD << endl;

  return 0;
}


Error: 0

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;
typedef long long ll;

const int MOD = 1000000007;

int main() {
  int N;
  cin >> N;

  vector<ll> pow2(N);
  pow2[0] = 1;
  for (int i = 1; i < N; i++) {
    pow2[i] = 2 * pow2[i - 1] % MOD;
  }

  map<pair<int, int>, int> m;
  for (int i = 0; i < N; i++) {
    int a, b;
    cin >> a >> b;
    int ta = a, tb = b;
    if (ta == 0 && tb == 0) {
      m[make_pair(0, 0)]++;
      continue;
    }
    if (ta == 0) {
      m[make_pair(0, 1)]++;
      continue;
    }
    if (tb == 0) {
      m[make_pair(1, 0)]++;
      continue;
    }
    while (ta != 0) {
      tb %= ta;
      swap(ta, tb);
    }
    a /= tb;
    b /= tb;
    if (a < 0) {
      a *= -1;
      b *= -1;
    }

    // cout << a << b << endl;
    m[make_pair(a, b)]++;
  }

  ll ans = 1;
  for (auto &mi : m) {
    if (mi.first.first == 0 && mi.first.second == 0)
      continue;
    pair<int, int> tmp;
    if (mi.first.second >= 0) {
      tmp.first = mi.first.second;
      tmp.second = -mi.first.first;
    } else {
      tmp.first = -mi.first.second;
      tmp.second = mi.first.first;
    }
    ll ansi = 0;
    ansi += pow2[m[tmp]];
    ansi += pow2[mi.second];
    ans *= ansi - 1;
    ans %= MOD;
    m[tmp] = 0;
    mi.second = 0;
  }

  cout << (ans - 1 + m[make_pair(0, 0)] + MOD) % MOD << endl;

  return 0;
}