Problem p02956 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define form2(i, a, b) for (int i = (a); i < (b); ++i)
#define ford2(i, a, b) for (int i = (a - 1); i >= (b); --i)
#define form(i, n) form2(i, 0, n)
#define ford(i, n) ford2(i, n, 0)

#define chmax(x, v) x = max(x, (v))
#define chmin(x, v) x = min(x, (v))
#define fi first
#define se second

const long long BIG = 1000000000000000000LL;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

void solve();
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  solve();
  return 0;
}

const int MOD = 998244353;
const int borne = 2 * (int)(1e5) + 5;
int fen[borne];

int getSom(int idx) {
  int res = 0;
  while (idx > 0) {
    res += fen[idx];
    idx -= idx & (-idx);
  }
  return res;
}

int getSom(int l, int r) {
  if (l > r)
    return 0;
  else
    return getSom(r) - getSom(l - 1);
}

void inc(int idx) {
  while (idx < borne) {
    fen[idx]++;
    idx += idx & (-idx);
  }
}

map<int, int> compX, compY;
pii pts[borne];
int quad[borne][4];
int nbPoints;

void docmp(vector<int> vec, map<int, int> &cmap) {
  sort(vec.begin(), vec.end());
  int sz = vec.size();
  form(i, sz) { cmap[vec[i]] = i + 1; }
}

int pm[borne];

int cmm(int x) {
  x %= MOD;
  x += MOD;
  x %= MOD;
  return x;
}
void solve() {
  cin >> nbPoints;
  vector<int> lx, ly;
  form(i, nbPoints) {
    int x, y;
    cin >> x >> y;
    lx.push_back(x);
    ly.push_back(y);
    pts[i] = {x, y};
  }
  docmp(lx, compX);
  docmp(ly, compY);
  form(i, nbPoints) {
    pts[i].fi += 30;
    pts[i].se += 30;
    // pts[i].fi = compX[pts[i].fi];
    // pts[i].se = compY[pts[i].se];
  }
  sort(pts, pts + nbPoints);
  form(i, nbPoints) {
    quad[i][0] = getSom(1, pts[i].se);
    quad[i][1] = getSom(pts[i].se, borne - 1);
    inc(pts[i].se);
  }
  form(i, borne) fen[i] = 0;
  ford(i, nbPoints) {
    quad[i][3] = getSom(1, pts[i].se);
    quad[i][2] = getSom(pts[i].se, borne - 1);
    inc(pts[i].se);
  }

  pm[0] = 1;
  form2(i, 1, borne) { pm[i] = cmm(2 * pm[i - 1]); }

  int res = 0;
  vector<int> v{0, 1, 2, 3};
  set<vector<int>> sp;
  do {
    form(c, 4) {
      vector<int> yw;
      form(i, c + 1) yw.push_back(v[i]);
      bool ok = false;
      for (int a : yw)
        for (int b : yw)
          if (a % 2 == b % 2 && a != b)
            ok = true;
      if (!ok)
        continue;
      sort(yw.begin(), yw.end());
      sp.insert(yw);
    }
  } while (next_permutation(v.begin(), v.end()));
  form(i, nbPoints) {
    for (auto yw : sp) {
      int subCnt = 1;
      for (int x : yw) {
        subCnt = cmm(subCnt * cmm(pm[quad[i][x]] - 1));
      }
      res = cmm(res + subCnt);
    }
    res = cmm(res + pm[nbPoints - 1]);
  }
  cout << res << "\n";
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define form2(i, a, b) for (int i = (a); i < (b); ++i)
#define ford2(i, a, b) for (int i = (a - 1); i >= (b); --i)
#define form(i, n) form2(i, 0, n)
#define ford(i, n) ford2(i, n, 0)

#define chmax(x, v) x = max(x, (v))
#define chmin(x, v) x = min(x, (v))
#define fi first
#define se second

const long long BIG = 1000000000000000000LL;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

void solve();
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  solve();
  return 0;
}

const int MOD = 998244353;
const int borne = 2 * (int)(1e5) + 5;
int fen[borne];

int getSom(int idx) {
  int res = 0;
  while (idx > 0) {
    res += fen[idx];
    idx -= idx & (-idx);
  }
  return res;
}

int getSom(int l, int r) {
  if (l > r)
    return 0;
  else
    return getSom(r) - getSom(l - 1);
}

void inc(int idx) {
  while (idx < borne) {
    fen[idx]++;
    idx += idx & (-idx);
  }
}

map<int, int> compX, compY;
pii pts[borne];
int quad[borne][4];
int nbPoints;

void docmp(vector<int> vec, map<int, int> &cmap) {
  sort(vec.begin(), vec.end());
  int sz = vec.size();
  form(i, sz) { cmap[vec[i]] = i + 1; }
}

int pm[borne];

int cmm(int x) {
  x %= MOD;
  x += MOD;
  x %= MOD;
  return x;
}
void solve() {
  cin >> nbPoints;
  vector<int> lx, ly;
  form(i, nbPoints) {
    int x, y;
    cin >> x >> y;
    lx.push_back(x);
    ly.push_back(y);
    pts[i] = {x, y};
  }
  docmp(lx, compX);
  docmp(ly, compY);
  form(i, nbPoints) {
    pts[i].fi = compX[pts[i].fi];
    pts[i].se = compY[pts[i].se];
  }
  sort(pts, pts + nbPoints);
  form(i, nbPoints) {
    quad[i][0] = getSom(1, pts[i].se);
    quad[i][1] = getSom(pts[i].se, borne - 1);
    inc(pts[i].se);
  }
  form(i, borne) fen[i] = 0;
  ford(i, nbPoints) {
    quad[i][3] = getSom(1, pts[i].se);
    quad[i][2] = getSom(pts[i].se, borne - 1);
    inc(pts[i].se);
  }

  pm[0] = 1;
  form2(i, 1, borne) { pm[i] = cmm(2 * pm[i - 1]); }

  int res = 0;
  vector<int> v{0, 1, 2, 3};
  set<vector<int>> sp;
  do {
    form(c, 4) {
      vector<int> yw;
      form(i, c + 1) yw.push_back(v[i]);
      bool ok = false;
      for (int a : yw)
        for (int b : yw)
          if (a % 2 == b % 2 && a != b)
            ok = true;
      if (!ok)
        continue;
      sort(yw.begin(), yw.end());
      sp.insert(yw);
    }
  } while (next_permutation(v.begin(), v.end()));
  form(i, nbPoints) {
    for (auto yw : sp) {
      int subCnt = 1;
      for (int x : yw) {
        subCnt = cmm(subCnt * cmm(pm[quad[i][x]] - 1));
      }
      res = cmm(res + subCnt);
    }
    res = cmm(res + pm[nbPoints - 1]);
  }
  cout << res << "\n";
}