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

// Marcin Knapik
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")

using namespace std;

// #include <ext/pb_ds/assoc_container.hpp> // order_of_key
// #include <ext/pb_ds/tree_policy.hpp> // find by order
// using namespace __gnu_pbds;
// #define ordered_set tree< int , null_type,less< int >,
// rb_tree_tag,tree_order_statistics_node_update>

// const ll MAX_LL = 0xFFFFFFFFFFFFFFFF;
// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define losuj(a, b) uniform_int_distribution<ull>(a, b)(rng)

typedef long double ld;
typedef long long ll;
typedef pair<ll, ll> ii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
#define pll pair<long long, long long>

#define sz(a) (int)(a).size()
#define pb push_back
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define FOR(i, a) for (int i = 0; i < (a); i++)
#define f first
#define s second

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

template <class T> inline T fast(T a, T b, T mod) {
  ll res = 1;
  while (b) {
    if (b & 1)
      res = (res * a) % mod;
    a = (a * a) % mod;
    b >>= 1;
  }
  return res;
}
template <class T> istream &operator>>(istream &os, vector<T> &container) {
  for (auto &u : container)
    os >> u;
  return os;
}
template <class T>
ostream &operator<<(ostream &os, const vector<T> &container) {
  for (auto &u : container)
    os << u << " ";
  return os;
}
template <class T> ostream &operator<<(ostream &os, const pair<T, T> &u) {
  os << u.f << " " << u.s << ' ';
  return os;
}
template <class T> inline T gcd(T a, T b) {
  while (b)
    swap(a %= b, b);
  return a;
}

const ll INF = 1e9 + 7;
const ll mod = 998244353;
const ll BIG_INF = 1e18;
const ll N = 1e6 + 7;
const ll T = 1 << 20;
const ld inf = 1e18;

ll n, m, q;

map<pair<ll, ll>, ll> mapa;

pll norm(pll x) {
  ll a = x.f, b = x.s;
  if (a == 0 or b == 0)
    return {a, b};
  if (a < 0 and b < 0) {
    a *= -1;
    b *= -1;
  }
  ll GCD = (gcd(abs(a), abs(b)));
  a /= GCD;
  b /= GCD;
  if (a < 0) {
    a *= -1;
    b *= -1;
  }
  return {a, b};
}

signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);

  cin >> n;
  FOR(i, n) {
    ll a, b;
    cin >> a >> b;

    mapa[norm({a, b})]++;
  }
  ll pref = 1;
  // for(auto & u : mapa){
  // 	cout << u.f << "    " << u.s << endl;
  // }
  // cout << endl;
  ll dwa_zera = 0;
  ll pierwsze_zero = 0;
  ll drugie_zero = 0;
  for (auto &u : mapa) {
    if (u.f.f == 0 and u.f.s == 0) {
      dwa_zera += u.s;
      continue;
    } else if (u.f.f == 0) {
      pierwsze_zero += u.s;
      continue;
    } else if (u.f.s == 0) {
      drugie_zero += u.s;
      continue;
    }
    pll opposite = norm({-u.f.s, u.f.f});
    // cout << u.f << ' ' << opposite << "     " << u.s << ' ' << mapa[opposite]
    // << endl;
    if (opposite < u.f) {
      ll pom = pref * fast(fast(2LL, mapa[opposite], INF), INF - 2, INF) % INF;
      // cout << "pom " << pom << endl;
      pref = pom *
             (fast(2LL, mapa[opposite], INF) + fast(2LL, u.s, INF) - 1 + INF) %
             INF;
    } else
      pref = pref * fast(2LL, u.s, INF) % INF;
    // cout << "PREF " << pref << endl;
  }
  // cout << pref << ' ' << drugie_zero << endl;
  pref =
      pref *
      (fast(2LL, pierwsze_zero, INF) + fast(2LL, drugie_zero, INF) - 1 + INF) %
      INF;
  pref += dwa_zera;
  cout << (pref - 1 + INF) % INF << '\\n';
}

Error: 0

Fixed submission:

// Marcin Knapik
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")

using namespace std;

// #include <ext/pb_ds/assoc_container.hpp> // order_of_key
// #include <ext/pb_ds/tree_policy.hpp> // find by order
// using namespace __gnu_pbds;
// #define ordered_set tree< int , null_type,less< int >,
// rb_tree_tag,tree_order_statistics_node_update>

// const ll MAX_LL = 0xFFFFFFFFFFFFFFFF;
// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define losuj(a, b) uniform_int_distribution<ull>(a, b)(rng)

typedef long double ld;
typedef long long ll;
typedef pair<ll, ll> ii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
#define pll pair<long long, long long>

#define sz(a) (int)(a).size()
#define pb push_back
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define FOR(i, a) for (int i = 0; i < (a); i++)
#define f first
#define s second

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

template <class T> inline T fast(T a, T b, T mod) {
  ll res = 1;
  while (b) {
    if (b & 1)
      res = (res * a) % mod;
    a = (a * a) % mod;
    b >>= 1;
  }
  return res;
}
template <class T> istream &operator>>(istream &os, vector<T> &container) {
  for (auto &u : container)
    os >> u;
  return os;
}
template <class T>
ostream &operator<<(ostream &os, const vector<T> &container) {
  for (auto &u : container)
    os << u << " ";
  return os;
}
template <class T> ostream &operator<<(ostream &os, const pair<T, T> &u) {
  os << u.f << " " << u.s << ' ';
  return os;
}
template <class T> inline T gcd(T a, T b) {
  while (b)
    swap(a %= b, b);
  return a;
}

const ll INF = 1e9 + 7;
const ll mod = 998244353;
const ll BIG_INF = 1e18;
const ll N = 1e6 + 7;
const ll T = 1 << 20;
const ld inf = 1e18;

ll n, m, q;

int snak[N];
int odw[N];
vvi G(N);

map<pair<ll, ll>, ll> mapa;

pll norm(pll x) {
  ll a = x.f, b = x.s;
  if (a < 0 and b < 0) {
    a *= -1;
    b *= -1;
  }
  ll GCD = (gcd(abs(a), abs(b)));
  a /= GCD;
  b /= GCD;
  if (a < 0) {
    a *= -1;
    b *= -1;
  }
  return {a, b};
}

signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);

  cin >> n;
  FOR(i, n) {
    ll a, b;
    cin >> a >> b;

    mapa[norm({a, b})]++;
  }
  ll pref = 1;
  // for(auto & u : mapa){
  // 	cout << u.f << "    " << u.s << endl;
  // }
  // cout << endl;

  for (auto &u : mapa) {
    pll opposite = norm({-u.f.s, u.f.f});
    if (opposite == u.f) {
      pref = (pref * (u.s + 1)) % INF;
      continue;
    }
    // cout << u.f << ' ' << opposite << "     " << u.s << ' ' << mapa[opposite]
    // << endl;
    if (opposite < u.f) {
      ll pom = pref * fast(fast(2LL, mapa[opposite], INF), INF - 2, INF) % INF;
      // cout << "pom " << pom << endl;
      pref = pom * (fast(2LL, mapa[opposite], INF) + fast(2LL, u.s, INF) - 1) %
             INF;
    } else
      pref = pref * fast(2LL, u.s, INF) % INF;
    // cout << "PREF " << pref << endl;
  }
  cout << (pref - 1) % INF << '\\n';
}