Problem p03283 (C++)

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

using namespace std;
using ll = long long;

#define rep(i, a) for (int i = 0; (i) < (int)(a); (i)++)
#define reps(i, a, b) for (int i = (int)(a); (i) < (int)(b); (i)++)
#define rrep(i, a) for (int i = (int)a - 1; (i) >= 0; (i)--)
#define rreps(i, a, b) for (int i = (int)(a)-1; (i) >= (int)(b); (i)--)
#define MP(a, b) make_pair((a), (b))
#define PB(a) push_back((a))
#define all(v) (v).begin(), (v).end()
#define PERM(v) next_permutation(all(v))
#define UNIQUE(v)                                                              \
  sort(all(v));                                                                \
  (v).erase(unique(all(v)), v.end())
#define CIN(type, x)                                                           \
  type x;                                                                      \
  cin >> x
#define TRUE__ "Yes"
#define FALSE__ "No"
#define PRINT(f)                                                               \
  if ((f)) {                                                                   \
    cout << (TRUE__) << endl;                                                  \
  } else {                                                                     \
    cout << FALSE__ << endl;                                                   \
  }
#define RS resize
#define CINV(v, N)                                                             \
  do {                                                                         \
    v.RS(N);                                                                   \
    rep(i, N) cin >> v[i];                                                     \
  } while (0);
#define RCINV(v, N)                                                            \
  do {                                                                         \
    v.RS(N);                                                                   \
    rrep(i, N) cin >> v[i];                                                    \
  } while (0);

#define MOD 1000000007
void init();
void solve();

signed main() {
  init();
  solve();
}

struct BIT {
  vector<vector<int>> node;
  int n;
  BIT(int n_) : node(n_ + 1, vector<int>(n_ + 1, 0)), n(n_ + 1) {}
  void add(int r, int c, int v) {
    for (int i = r + 1; i <= n; i += i & -i) {
      for (int j = c + 1; j <= n; j += j & -j) {
        node[i][j] += v;
      }
    }
  }
  int get(int r, int c) {
    int res = 0;
    for (int i = r + 1; i; i -= i & -i) {
      for (int j = c + 1; j; j -= j & -j) {
        res += node[i][j];
      }
    }
    return res;
  }
  int get_sum(int r1, int c1, int r2, int c2) {
    return get(r2, c2) - get(r1, c2) - get(r2, c1) + get(r1, c1);
  }
};

void init() {
  int N, M, Q;
  cin >> N >> M >> Q;
  BIT bit(N);
  rep(i, M) {
    int l, r;
    cin >> l >> r;
    l--;
    r--;
    bit.add(l, r, 1);
  }
  rep(i, Q) {
    int l, r;
    cin >> l >> r;
    l -= 2;
    r--;
    cout << bit.get_sum(l, l, r, r) << endl;
  }
}

void solve() {}

Fixed submission:
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

#define rep(i, a) for (int i = 0; (i) < (int)(a); (i)++)
#define reps(i, a, b) for (int i = (int)(a); (i) < (int)(b); (i)++)
#define rrep(i, a) for (int i = (int)a - 1; (i) >= 0; (i)--)
#define rreps(i, a, b) for (int i = (int)(a)-1; (i) >= (int)(b); (i)--)
#define MP(a, b) make_pair((a), (b))
#define PB(a) push_back((a))
#define all(v) (v).begin(), (v).end()
#define PERM(v) next_permutation(all(v))
#define UNIQUE(v)                                                              \
  sort(all(v));                                                                \
  (v).erase(unique(all(v)), v.end())
#define CIN(type, x)                                                           \
  type x;                                                                      \
  cin >> x
#define TRUE__ "Yes"
#define FALSE__ "No"
#define PRINT(f)                                                               \
  if ((f)) {                                                                   \
    cout << (TRUE__) << endl;                                                  \
  } else {                                                                     \
    cout << FALSE__ << endl;                                                   \
  }
#define RS resize
#define CINV(v, N)                                                             \
  do {                                                                         \
    v.RS(N);                                                                   \
    rep(i, N) cin >> v[i];                                                     \
  } while (0);
#define RCINV(v, N)                                                            \
  do {                                                                         \
    v.RS(N);                                                                   \
    rrep(i, N) cin >> v[i];                                                    \
  } while (0);

#define MOD 1000000007
void init();
void solve();

signed main() {
  init();
  solve();
}

struct BIT {
  vector<vector<int>> node;
  int n;
  BIT(int n_) : node(n_ + 1, vector<int>(n_ + 1, 0)), n(n_ + 1) {}
  void add(int r, int c, int v) {
    for (int i = r + 1; i <= n; i += i & -i) {
      for (int j = c + 1; j <= n; j += j & -j) {
        node[i][j] += v;
      }
    }
  }
  int get(int r, int c) {
    int res = 0;
    for (int i = r + 1; i; i -= i & -i) {
      for (int j = c + 1; j; j -= j & -j) {
        res += node[i][j];
      }
    }
    return res;
  }
  int get_sum(int r1, int c1, int r2, int c2) {
    return get(r2, c2) - get(r1, c2) - get(r2, c1) + get(r1, c1);
  }
};

void init() {
  int N, M, Q;
  cin >> N >> M >> Q;
  BIT bit(N + 20);
  rep(i, M) {
    int l, r;
    cin >> l >> r;
    l--;
    r--;
    bit.add(l, r, 1);
  }
  rep(i, Q) {
    int l, r;
    cin >> l >> r;
    l -= 2;
    r--;
    cout << bit.get_sum(l, l, r, r) << endl;
  }
}

void solve() {}