prithivMLmods/Coder-Stat huggingface dataset:
Problem p03282 (C++)

Buggy submission (status: Runtime Error):
#include <cmath>
#include <iostream>

typedef long long ll;

int main() {
  std::string S;
  ll K;
  std::cin >> S >> K;

  int N = S.size();
  int T[N];
  for (int i = 0; i < N; ++i) {
    for (char j = '1'; j <= '9'; ++j) {
      if (j == S[i]) {
        T[i] = j - '0';
        break;
      }
    }
  }

  int n = 0;
  for (int i = 0; i < N; ++i) {
    if (T[i] > 1)
      break;
    else
      ++n;
  }
  if (K <= n)
    std::cout << T[0] << std::endl;
  else
    std::cout << T[n] << std::endl;

  /*
  ll ndays = 5000000000000000;
  ll n = 0;
  for(int i=0; i<N; ++i){
     std::cout << i << ' ' << T[i] << std::endl;
     ll m = 1;
     if(T[i]>1){
        for(int j=0; j<ndays; ++j){
           m *= T[i];
           if(m>K){
              std::cout << T[i] << std::endl;
              return 0;
           }
        }
     }
     n += pow(T[i],ndays);
     std::cout << n << std::endl;
     if(n>K) {
        std::cout << T[i] << std::endl;
        return 0;
     }
  }*/

  return -1;
}


Fixed submission:
#include <cmath>
#include <iostream>

typedef long long ll;

int main() {
  std::string S;
  ll K;
  std::cin >> S >> K;

  int N = S.size();
  int T[N];
  for (int i = 0; i < N; ++i) {
    for (char j = '1'; j <= '9'; ++j) {
      if (j == S[i]) {
        T[i] = j - '0';
        break;
      }
    }
  }

  int n = 0;
  for (int i = 0; i < N; ++i) {
    if (T[i] > 1)
      break;
    else
      ++n;
  }
  if (K <= n)
    std::cout << T[0] << std::endl;
  else
    std::cout << T[n] << std::endl;

  /*
  ll ndays = 5000000000000000;
  ll n = 0;
  for(int i=0; i<N; ++i){
     std::cout << i << ' ' << T[i] << std::endl;
     ll m = 1;
     if(T[i]>1){
        for(int j=0; j<ndays; ++j){
           m *= T[i];
           if(m>K){
              std::cout << T[i] << std::endl;
              return 0;
           }
        }
     }
     n += pow(T[i],ndays);
     std::cout << n << std::endl;
     if(n>K) {
        std::cout << T[i] << std::endl;
        return 0;
     }
  }*/

  return 0;
}
Problem p03282 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <string>
#include <vector>

typedef long long ll;
typedef unsigned long long ull;

int main() {
  std::string s;
  ll k;
  ll ans = 0;
  bool b = false;
  std::cin >> s >> k;

  for (ll i = 0; i < k; ++i) {
    if (s[i] != '1') {
      ans = i;
      b = true;
    }
  }
  if (b) {
    std::cout << s[ans] << std::endl;
  } else {
    std::cout << 1 << std::endl;
  }
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <string>
#include <vector>

typedef long long ll;
typedef unsigned long long ull;

int main() {
  std::string s;
  ll k;
  ll ans = 0;
  bool b = false;
  std::cin >> s >> k;
  if (k > s.size()) {
    for (ll i = 0; i < s.size(); ++i) {
      if (s[i] != '1') {
        ans = i;
        b = true;
        break;
      }
    }
  } else {
    for (ll i = 0; i < k; ++i) {
      if (s[i] != '1') {
        ans = i;
        b = true;
        break;
      }
    }
  }
  if (b) {
    std::cout << s[ans] << std::endl;
  } else {
    std::cout << 1 << std::endl;
  }
}
Problem p03282 (Python)

Buggy submission (status: Runtime Error):
s = input()
k = int(input())
if len(s) == 1 or k == 1:
    print(s[0])
i = 0
while i < k and i < len(s):
    if s[i] != "1":
        break
    i += 1
print(s[i])


Fixed submission:
s = input()
k = int(input())
if len(s) == 1 or k == 1:
    print(s[0])
else:
    i = 0
    while i < k - 1 and i < len(s):
        if s[i] != "1":
            break
        i += 1
    print(s[i])
Problem p03282 (Python)

Buggy submission (status: Runtime Error):
s = input()
k = int(input())
if s[0] != "1":
    print(s[0])
else:
    print(s[1])


Fixed submission:
s = input()
k = int(input())
for i in range(len(s)):
    if s[i] != "1":
        print(s[i])
        exit()
    else:
        if i == len(s) - 1:
            print("1")
            exit()
        if i + 1 == k:
            print("1")
            exit()
Problem p03282 (Python)

Buggy submission (status: Runtime Error):
S = input()
K = int(input())
if S[0] != "1":
    print(S[0])
else:
    ind = 1
    while S[ind] == "1" and ind < len(S) - 1:
        ind += 1
    if ind < K:
        print(S[ind])
    else:
        print("1")


Fixed submission:
S = input()
K = int(input())
if S[0] != "1":
    print(S[0])
else:
    ind = 0
    while S[ind] == "1" and ind < len(S) - 1:
        ind += 1
    if ind < K:
        print(S[ind])
    else:
        print("1")
Problem p03282 (Python)

Buggy submission (status: Runtime Error):
s = input()
k = int(input())

if s[0] == "1":
    print(s[1])
else:
    print(s[0])


Fixed submission:
s = input()
k = int(input())

limit = min(100, k)

ans = 1
for i in range(limit):
    if s[i] != "1":
        ans = s[i]
        break

print(ans)
Problem p03282 (Python)

Buggy submission (status: Runtime Error):
S = input()
K = int(input())
ret = "1"
for i in K:
    if len(S) <= K:
        break
    if S[i] != "1":
        ret = S[i]
        break
print(ret)


Fixed submission:
S = input()
K = int(input())
ret = "1"
for i in range(K):
    if len(S) < i - 1:
        break
    if S[i] != "1":
        ret = S[i]
        break
print(ret)
Problem p03282 (Python)

Buggy submission (status: Runtime Error):
s = input()
k = int(input())

if s[0] != "1":
    print(s[1])


Fixed submission:
s = input()
k = int(input())

for i in range(k):
    if s[i] != "1":
        print(s[i])
        break
else:
    print("1")
Problem p03282 (Python)

Buggy submission (status: Runtime Error):
S = input()
K = int(input())
if len(S) > K and S[:K].count(1) == K:
    print(1)
else:
    for c in S:
        if c != "1":
            print(c)
            break


Fixed submission:
S = input()
K = int(input())
if len(S) >= K and S[:K].count("1") == K:
    print(1)
else:
    for c in S:
        if c != "1":
            print(c)
            break
Problem p03282 (Python)

Buggy submission (status: Runtime Error):
import re

S = input().rstrip()
K = int(input())

i = re.search(r"[2-9]", S).start()

if K < i + 1:
    print(1)
else:
    if S[0] == "1":
        print(S[i])
    else:
        print(S[0])


Fixed submission:
import re

S = input().rstrip()
K = int(input())

reg = re.search(r"[2-9]", S)
if reg:
    i = reg.start()
else:
    i = len(S) + 1


if K < i + 1:
    print(1)
else:
    if S[0] == "1":
        print(S[i])
    else:
        print(S[0])
Problem p03282 (Python)

Buggy submission (status: Runtime Error):
# -*- coding: utf-8 -*-
"""
Created on Sat May  9 16:54:06 2020

@author: shinba
"""

s = input()
k = int(input())

cnt = 0

while s[cnt] == "1":
    cnt += 1

if cnt >= k:
    print(1)
else:
    print(s[cnt])


Fixed submission:
# -*- coding: utf-8 -*-
"""
Created on Sat May  9 16:54:06 2020

@author: shinba
"""

s = input()
k = int(input())

cnt = 0

while s[cnt] == "1":
    cnt += 1
    if cnt == len(s):
        break

if cnt >= k:
    print(1)
else:
    print(s[cnt])
Problem p03282 (Python)

Buggy submission (status: Runtime Error):
import sys


S = [int(_) for _ in list(input())]
K = int(input())
t = 0
while t <= len(S):
    if S[t] == 1:
        t += 1
    else:
        break

if K <= t:
    print(1)
    sys.exit()
else:
    print(S[t])
    sys.exit()


Fixed submission:
import sys


S = [int(_) for _ in list(input())]
K = int(input())
t = 0
while t <= len(S) - 1:
    if S[t] == 1:
        t += 1
    else:
        break

if K <= t:
    print(1)
    sys.exit()
else:
    print(S[t])
    sys.exit()
Problem p03283 (C++)

Buggy submission (status: Runtime Error):
#include <stdio.h>

int main() {
  int i, j;
  int M, N, Q;
  int p, q;
  int **LR;
  int acc;
  scanf("%d %d %d", &M, &N, &Q);
  LR = new int *[N];
  for (i = 0; i < N; i++) {
    LR[i] = new int[N - i]();
  }

  for (i = 0; i < M; i++) {
    scanf("%d %d", &p, &q);
    LR[p - 1][q - p] += 1;
  }

  for (i = N - 2; 0 <= i; i--) {
    acc = 0;
    for (j = 0; j < N - i; j++) {
      acc += LR[i][j];
      LR[i][j] = acc + LR[i + 1][j - 1];
    }
  }

  for (i = 0; i < Q; i++) {
    scanf("%d %d", &p, &q);
    printf("%d\n", LR[p - 1][q - p]);
  }
  return 0;
}

Fixed submission:
#include <stdio.h>

int main() {
  int i, j;
  int M, N, Q;
  int p, q;
  int **LR;
  int acc;
  scanf("%d %d %d", &N, &M, &Q);
  LR = new int *[N];
  for (i = 0; i < N; i++) {
    LR[i] = new int[N - i]();
  }

  for (i = 0; i < M; i++) {
    scanf("%d %d", &p, &q);
    LR[p - 1][q - p] += 1;
  }

  for (i = N - 2; 0 <= i; i--) {
    acc = 0;
    for (j = 0; j < N - i; j++) {
      acc += LR[i][j];
      LR[i][j] = acc + LR[i + 1][j - 1];
    }
  }

  for (i = 0; i < Q; i++) {
    scanf("%d %d", &p, &q);
    printf("%d\n", LR[p - 1][q - p]);
  }
  return 0;
}
Problem p03283 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <vector>

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for (ll i = n - 1; i >= 0; i--)
#define repone(i, n) for (ll i = 1; i <= (ll)(n); i++)
#define each(i, mp) for (auto i : mp)
#define FOR(i, m, n) for (ll i = m; i < n; i++)
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll half_inf = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);

ll n, m, Q;
vector<ll> l, r;
vector<ll> p, q;

void solve() {
  ll d[n + 1][n + 1];
  fill(d[0], d[n + 1], 0);
  rep(i, m) d[l[i]][r[i]]++;
  ll dp[n + 1][n + 1];
  fill(dp[0], dp[n + 1], 0);
  repone(i, n) {
    repone(j, n) { dp[i][j] = dp[i][j - 1] + d[i][j]; }
  }
  rep(i, Q) {
    ll ans = 0;
    for (ll j = p[i]; j <= q[i]; ++j)
      ans += dp[j][q[i]] - dp[j][p[i] - 1];
    cout << ans << endl;
  }
}

int main() {
  cin >> n >> m >> Q;
  l.resize(n), r.resize(n);
  p.resize(Q), q.resize(Q);
  rep(i, m) cin >> l[i] >> r[i];
  rep(i, Q) cin >> p[i] >> q[i];
  solve();
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <vector>

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for (ll i = n - 1; i >= 0; i--)
#define repone(i, n) for (ll i = 1; i <= (ll)(n); i++)
#define each(i, mp) for (auto i : mp)
#define FOR(i, m, n) for (ll i = m; i < n; i++)
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll half_inf = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);

ll n, m, Q;
vector<ll> l, r;
vector<ll> p, q;

void solve() {
  ll d[n + 1][n + 1];
  fill(d[0], d[n + 1], 0);
  rep(i, m) d[l[i]][r[i]]++;
  ll dp[n + 1][n + 1];
  fill(dp[0], dp[n + 1], 0);
  repone(i, n) {
    repone(j, n) { dp[i][j] = dp[i][j - 1] + d[i][j]; }
  }
  rep(i, Q) {
    ll ans = 0;
    for (ll j = p[i]; j <= q[i]; ++j)
      ans += dp[j][q[i]] - dp[j][p[i] - 1];
    cout << ans << endl;
  }
}

int main() {
  cin >> n >> m >> Q;
  l.resize(m), r.resize(m);
  p.resize(Q), q.resize(Q);
  rep(i, m) cin >> l[i] >> r[i];
  rep(i, Q) cin >> p[i] >> q[i];
  solve();
  return 0;
}
Problem p03283 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>     // minmax, sort, swap
#include <climits>       // INT_MIN, LLONG_MIN
#include <cmath>         // long, trig, pow
#include <cstdint>       // int64_t, int_fast64_t
#include <cstdio>        // printf, scanf
#include <iomanip>       // cout<<setprecision(n)
#include <iostream>      // cin, cout, cerr, clog
#include <map>           // key-value pairs sorted by keys
#include <numeric>       // iota, gcd, lcm
#include <queue>         // queue
#include <set>           // set
#include <stack>         // stack
#include <string>        // string
#include <unordered_map> // hashed by keys
#include <unordered_set> // hashed by keys
#include <vector>        // vector

#define rep(i, n) for (int i = 0; i < n; i++)
#define ENDL "\n"

typedef std::int_fast64_t ll;   // at least int64 > 9*10^18
typedef std::uint_fast64_t ull; // at least uint64

#define int ll

#define INF 10101010

struct FastIO {
  FastIO() {
    std::cin.tie(0);
    std::ios_base::sync_with_stdio(0);
  }
} fastio;

signed main() {
  int n, m, q;
  std::cin >> n >> m >> q;
  std::vector<std::vector<int>> trains(n, std::vector<int>(n, 0));
  rep(i, m) {
    int l, r;
    std::cin >> l >> r;
    l--;
    r--;
    trains[l][r]++;
  }
  rep(i, q) {
    int l, r;
    std::cin >> l >> r;
    l--;
    r--;
    int count = 0;
    for (int x = l; x <= r; x++) {
      for (int y = r; y >= x; y--) {
        count += trains[x][y];
      }
    }
    std::cout << count << ENDL;
  }
  return 0;
}

Fixed submission:
#include <algorithm>     // minmax, sort, swap
#include <climits>       // INT_MIN, LLONG_MIN
#include <cmath>         // long, trig, pow
#include <cstdint>       // int64_t, int_fast64_t
#include <cstdio>        // printf, scanf
#include <iomanip>       // cout<<setprecision(n)
#include <iostream>      // cin, cout, cerr, clog
#include <map>           // key-value pairs sorted by keys
#include <numeric>       // iota, gcd, lcm
#include <queue>         // queue
#include <set>           // set
#include <stack>         // stack
#include <string>        // string
#include <unordered_map> // hashed by keys
#include <unordered_set> // hashed by keys
#include <vector>        // vector

#define rep(i, n) for (int i = 0; i < n; i++)
#define ENDL "\n"

typedef std::int_fast64_t ll;   // at least int64 > 9*10^18
typedef std::uint_fast64_t ull; // at least uint64

#define int ll

#define INF 10101010

struct FastIO {
  FastIO() {
    std::cin.tie(0);
    std::ios_base::sync_with_stdio(0);
  }
} fastio;

signed main() {
  int n, m, q;
  std::cin >> n >> m >> q;
  std::vector<std::vector<int>> trains(n, std::vector<int>(n, 0));
  rep(i, m) {
    int l, r;
    std::cin >> l >> r;
    l--;
    r--;
    trains[l][r]++;
  }
  rep(i, q) {
    int l, r;
    std::cin >> l >> r;
    if (l == 1 && r == n) {
      std::cout << m << ENDL;
      continue;
    }
    l--;
    r--;
    int count = 0;
    for (int x = l; x <= r; x++) {
      for (int y = r; y >= x; y--) {
        count += trains[x][y];
      }
    }
    std::cout << count << ENDL;
  }
  return 0;
}
Problem p03283 (C++)

Buggy submission (status: Runtime Error):
#include <stdio.h>

int main() {
  int i, j;
  int M, N, Q;
  int p, q;
  int LR[256][256];
  int acc;
  scanf("%d %d %d", &N, &M, &Q);

  for (i = 0; i < M; i++) {
    scanf("%d %d", &p, &q);
    LR[p - 1][q - p] += 1;
  }

  for (i = N - 2; 0 <= i; i--) {
    acc = 0;
    for (j = 0; j < N - i; j++) {
      acc += LR[i][j];
      LR[i][j] = acc + LR[i + 1][j - 1];
    }
  }

  for (i = 0; i < Q; i++) {
    scanf("%d %d", &p, &q);
    printf("%d\n", LR[p - 1][q - p]);
  }
  return 0;
}

Fixed submission:
#include <stdio.h>

int main() {
  int i, j;
  int M, N, Q;
  int p, q;
  int LR[512][512];
  int acc;
  scanf("%d %d %d", &N, &M, &Q);

  for (i = 0; i < M; i++) {
    scanf("%d %d", &p, &q);
    LR[p - 1][q - p] += 1;
  }

  for (i = N - 2; 0 <= i; i--) {
    acc = 0;
    for (j = 0; j < N - i; j++) {
      acc += LR[i][j];
      LR[i][j] = acc + LR[i + 1][j - 1];
    }
  }

  for (i = 0; i < Q; i++) {
    scanf("%d %d", &p, &q);
    printf("%d\n", LR[p - 1][q - p]);
  }
  return 0;
}
Problem p03283 (C++)

Buggy submission (status: Runtime Error):
#pragma GCC optimize("O3")

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() { cerr << endl; }

template <typename H, typename... T> void d_err(H h, T... t) {
  cerr << h << " ";
  d_err(t...);
}

template <typename T> void print(T x) { cout << x << "\n"; }

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REVFOR(i, m, n) for (int i = (n - 1); i >= (m); --i)
#define REP(i, n) FOR(i, 0, n)
#define REVREP(i, n) REVFOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll, ll> Pll;
typedef pair<int, int> Pin;

ll INF = 1e16;
int inf = 1e9;

void chmax(ll &x, ll y) {
  if (x < y)
    x = y;
}

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(20);

  int n, m, q;
  cin >> n >> m >> q;

  vi L(m), R(m);
  REP(i, m) cin >> L[i] >> R[i];

  const int MAX = 11;
  vector<vll> s(MAX, vll(MAX, 0));
  REP(i, m) { s[MAX - L[i]][R[i]]++; }

  FOR(i, 1, MAX) FOR(j, 1, MAX) {
    s[i][j] += s[i - 1][j] + s[i][j - 1] - s[i - 1][j - 1];
  }

  debug(s);

  REP(_, q) {
    int l, r;
    cin >> l >> r;
    int sl = MAX - l, sr = MAX - r;

    print(s[sl][r] + s[sr - 1][l - 1] - s[sl][l - 1] - s[sr - 1][r]);
  }
}

Fixed submission:
#pragma GCC optimize("O3")

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() { cerr << endl; }

template <typename H, typename... T> void d_err(H h, T... t) {
  cerr << h << " ";
  d_err(t...);
}

template <typename T> void print(T x) { cout << x << "\n"; }

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REVFOR(i, m, n) for (int i = (n - 1); i >= (m); --i)
#define REP(i, n) FOR(i, 0, n)
#define REVREP(i, n) REVFOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll, ll> Pll;
typedef pair<int, int> Pin;

ll INF = 1e16;
int inf = 1e9;

void chmax(ll &x, ll y) {
  if (x < y)
    x = y;
}

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(20);

  int n, m, q;
  cin >> n >> m >> q;

  vi L(m), R(m);
  REP(i, m) cin >> L[i] >> R[i];

  const int MAX = 1000;
  vector<vll> s(MAX, vll(MAX, 0));
  REP(i, m) { s[MAX - L[i]][R[i]]++; }

  FOR(i, 1, MAX) FOR(j, 1, MAX) {
    s[i][j] += s[i - 1][j] + s[i][j - 1] - s[i - 1][j - 1];
  }

  debug(s);

  REP(_, q) {
    int l, r;
    cin >> l >> r;
    int sl = MAX - l, sr = MAX - r;

    print(s[sl][r] + s[sr - 1][l - 1] - s[sl][l - 1] - s[sr - 1][r]);
  }
}
Problem p03283 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstdio>
#include <vector>
using namespace std;
int main() {
  int n, m, q;
  vector<int> a[500];
  scanf("%d%d%d", &n, &m, &q);
  for (int i = 0; i < m; i++) {
    int l, r;
    scanf("%d%d", &(l), &(r));
    a[l].push_back(r);
  }
  for (int i = 1; i <= 500; i++) {
    sort(a[i].begin(), a[i].end());
  }
  for (int i = 1; i <= q; i++) {
    int ll, rr;
    int ans = 0;
    scanf("%d%d", &(ll), &(rr));
    for (int j = ll; j <= rr; j++) {
      ans += upper_bound(a[j].begin(), a[j].end(), rr) - a[j].begin();
    }
    printf("%d\n", ans);
  }
}


Fixed submission:
#include <algorithm>
#include <cstdio>
#include <vector>
using namespace std;
int main() {
  int n, m, q;
  vector<int> a[550];
  scanf("%d%d%d", &n, &m, &q);
  for (int i = 0; i < m; i++) {
    int l, r;
    scanf("%d%d", &(l), &(r));
    a[l].push_back(r);
  }
  for (int i = 1; i <= 500; i++) {
    sort(a[i].begin(), a[i].end());
  }
  for (int i = 1; i <= q; i++) {
    int ll, rr;
    int ans = 0;
    scanf("%d%d", &(ll), &(rr));
    for (int j = ll; j <= rr; j++) {
      ans += upper_bound(a[j].begin(), a[j].end(), rr) - a[j].begin();
    }
    printf("%d\n", ans);
  }
}
Problem p03283 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
const constexpr int INF = 1e9;
// typedef std::pair<std::string,double> P;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)

typedef long long ll;
typedef vector<int> VI;
const constexpr ll MOD = 1e9 + 7;
vector<pair<int, int>> vp;

struct Less {
  bool operator()(const pair<int, int> &x, const pair<int, int> &y) const {
    return x.first > y.first;
  }
};

ll GCD(ll a, ll b) {
  if (b == 0)
    return a;
  return GCD(b, a % b);
}

// グラフの隣接リスト
VI g[200010];
// 頂点の入次数を管理
int h[100010];

vector<int> v;
int L[501], R[501];
int C[501][501], X[501][501];
int main(void) {

  ll N, M, Q;
  cin >> N >> M >> Q;
  REP(i, M) {
    cin >> L[i] >> R[i];
    X[L[i]][R[i]]++;
  }
  for (int i = 1; i <= N; ++i) {
    for (int j = 1; j <= N; ++j)
      C[i][j] = C[i][j - 1] + X[i][j];
  }
  for (int i = 0; i < Q; ++i) {
    int p, q;
    cin >> p >> q;
    int ans = 0;
    for (int j = p; j <= q; ++j)
      ans += C[j][q] - C[j][p - 1];
    cout << ans << endl;
  }

  return 0;
}

Fixed submission:
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
const constexpr int INF = 1e9;
// typedef std::pair<std::string,double> P;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)

typedef long long ll;
typedef vector<int> VI;
const constexpr ll MOD = 1e9 + 7;
vector<pair<int, int>> vp;

struct Less {
  bool operator()(const pair<int, int> &x, const pair<int, int> &y) const {
    return x.first > y.first;
  }
};

ll GCD(ll a, ll b) {
  if (b == 0)
    return a;
  return GCD(b, a % b);
}

// グラフの隣接リスト
VI g[200010];
// 頂点の入次数を管理
int h[100010];

vector<int> v;
int L[200009], R[200009];
int C[510][510], X[510][510];
int main(void) {

  ll N, M, Q;
  cin >> N >> M >> Q;
  REP(i, M) {
    cin >> L[i] >> R[i];
    X[L[i]][R[i]]++;
  }
  for (int i = 1; i <= N; ++i) {
    for (int j = 1; j <= N; ++j)
      C[i][j] = C[i][j - 1] + X[i][j];
  }
  for (int i = 0; i < Q; ++i) {
    int p, q;
    cin >> p >> q;
    int ans = 0;
    for (int j = p; j <= q; ++j)
      ans += C[j][q] - C[j][p - 1];
    cout << ans << endl;
  }

  return 0;
}
Problem p03283 (C++)

Buggy submission (status: Time Limit Exceeded):

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <vector>
using namespace std;

int main() {
  int N, M, Q, i, j, k, l, m;
  int L1R1[501][501];
  for (i = 0; i < 501; i++) {
    for (j = 0; j < 501; j++) {
      L1R1[i][j] = 0;
    }
  }
  cin >> N >> M >> Q;
  vector<int> L(M);
  vector<int> R(M);
  vector<int> p(Q);
  vector<int> q(Q);

  for (i = 0; i < M; i++) {
    cin >> L[i] >> R[i];
    L1R1[L[i]][R[i]]++;
  }
  for (i = 0; i < Q; i++) {
    cin >> p[i] >> q[i];
  }
  for (i = 0; i < 501; i++) {
    for (j = 1; j < 501; j++) {
      L1R1[i][j] += L1R1[i][j - 1];
    }
  }
  for (i = 500; i > 0; i++) {
    for (j = 0; j < 501; j++) {
      L1R1[i - 1][j] += L1R1[i][j];
    }
  }
  for (i = 0; i < Q; i++) {
    cout << L1R1[p[i]][q[i]] << endl;
  }

  return 0;
}


Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <vector>
using namespace std;

int main() {
  int N, M, Q, i, j, k, l, m;
  int L1R1[501][501];
  for (i = 0; i < 501; i++) {
    for (j = 0; j < 501; j++) {
      L1R1[i][j] = 0;
    }
  }
  cin >> N >> M >> Q;
  vector<int> L(M);
  vector<int> R(M);
  vector<int> p(Q);
  vector<int> q(Q);

  for (i = 0; i < M; i++) {
    cin >> L[i] >> R[i];
    L1R1[L[i]][R[i]]++;
  }
  for (i = 0; i < Q; i++) {
    cin >> p[i] >> q[i];
  }
  for (i = 0; i < 501; i++) {
    for (j = 1; j < 501; j++) {
      L1R1[i][j] += L1R1[i][j - 1];
    }
  }
  for (i = 500; i > 0; i--) {
    for (j = 0; j < 501; j++) {
      L1R1[i - 1][j] += L1R1[i][j];
    }
  }
  for (i = 0; i < Q; i++) {
    cout << L1R1[p[i]][q[i]] << endl;
  }

  return 0;
}
Problem p03283 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'
#define FASTINOUT                                                              \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL);                                                               \
  cout.tie(NULL);
const ll mod = 1000000007;
const double PI = 3.141592653589793238463;
const int N = 1e3 + 9;
vector<int> v[N];
int main() {
  FASTINOUT;
  int x, m, q;
  cin >> x >> m >> q;
  int r, l, ans = 0;
  for (int i = 0; i < m; i++) {
    cin >> l >> r;
    v[l].push_back(r);
  }
  for (int i = 1; i <= m; i++) {
    sort(v[i].begin(), v[i].end());
  }
  for (int i = 0; i < q; i++) {
    cin >> l >> r;
    ans = 0;
    for (int i = l; i <= r; i++) {
      ans += upper_bound(v[i].begin(), v[i].end(), r) - v[i].begin();
      // cout<<upper_bound(v[i].begin(),v[i].end(),r)-v[i].begin()<<endl;
    }
    cout << ans << endl;
  }
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'
#define FASTINOUT                                                              \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL);                                                               \
  cout.tie(NULL);
const ll mod = 1000000007;
const double PI = 3.141592653589793238463;
const int N = 2e5 + 9;
vector<int> v[N];
int main() {
  FASTINOUT;
  int x, m, q;
  cin >> x >> m >> q;
  int r, l, ans = 0;
  for (int i = 0; i < m; i++) {
    cin >> l >> r;
    v[l].push_back(r);
  }
  for (int i = 1; i <= m; i++) {
    sort(v[i].begin(), v[i].end());
  }
  for (int i = 0; i < q; i++) {
    cin >> l >> r;
    ans = 0;
    for (int i = l; i <= r; i++) {
      ans += upper_bound(v[i].begin(), v[i].end(), r) - v[i].begin();
      // cout<<upper_bound(v[i].begin(),v[i].end(),r)-v[i].begin()<<endl;
    }
    cout << ans << endl;
  }
  return 0;
}
Problem p03283 (C++)

Buggy submission (status: Time Limit Exceeded):
#include "bits/stdc++.h"
using namespace std;
#define rep(i, a, n) for (ll i = a; i < n; i++)
#define ALL(s) s.begin(), s.end()
#define P pair<ll, ll>
#define vl vector<ll>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vvl vector<vector<ll>>
#define print(n) cout << n << endl
const int M = 100010;
const int inf = 1000000007;
const long long INF = 1000000000000000007;
using ll = long long;
int dx[4] = {-1, 0, 1, 0}, dy[4] = {0, -1, 0, 1};

int main() {
  int n, m, Q, r, l, p, q;
  int pass[501][501] = {}, dp[501][501] = {};
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n >> m >> Q;
  rep(i, 0, m) {
    cin >> l >> r;
    rep(j, 0, l + 1) rep(k, r, 501) pass[j][k]++;
  }
  rep(i, 1, 501) rep(j, i, 501) {
    rep(k, i, j + 1) rep(l, k, j + 1) { dp[i][j] = max(dp[i][j], pass[k][l]); }
  }
  rep(i, 0, Q) {
    cin >> p >> q;
    print(dp[p][q]);
  }
}


Fixed submission:
#include "bits/stdc++.h"
using namespace std;
#define rep(i, a, n) for (ll i = a; i < n; i++)
#define ALL(s) s.begin(), s.end()
#define P pair<ll, ll>
#define vl vector<ll>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vvl vector<vector<ll>>
#define print(n) cout << n << endl
const int M = 100010;
const int inf = 1000000007;
const long long INF = 1000000000000000007;
using ll = long long;
int dx[4] = {-1, 0, 1, 0}, dy[4] = {0, -1, 0, 1};

int main() {
  int n, m, Q, r, l, p, q;
  int pass[501][501] = {}, dp[501][501] = {};
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n >> m >> Q;
  rep(i, 0, m) {
    cin >> l >> r;
    rep(j, 0, l + 1) rep(k, r, 501) pass[j][k]++;
  }
  rep(i, 1, 501) {
    rep(j, i, 501) {
      rep(k, 0, j - i + 1) dp[i][j] = max(dp[i][j], pass[i + k][j]);
    }
  }
  rep(i, 0, Q) {
    cin >> p >> q;
    print(dp[p][q]);
  }
}
Problem p03283 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <math.h>
#include <queue>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <vector>
using namespace std;
int N, M, Q;

vector<vector<long long int>> A(500, vector<long long int>(500, 0));

int main(void) {
  int l, r;
  cin >> N >> M >> Q;

  for (int i = 0; i < M; i++) {
    cin >> l >> r;
    A[r][l]++;
  }

  for (int i = 1; i <= N; i++)
    for (int j = 1; j <= N; j++) {
      A[i][j] += A[i - 1][j];
      A[i][j] += A[i][j - 1];
      A[i][j] -= A[i - 1][j - 1];
    }
  for (int i = 0; i < Q; i++) {
    cin >> l >> r;
    std::cout << A[r][r] - A[r][l - 1] - A[l - 1][r] + A[l - 1][l - 1]
              << std::endl;
  }

  return 0;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <math.h>
#include <queue>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <vector>
using namespace std;
int N, M, Q;

vector<vector<long long int>> A(550, vector<long long int>(550, 0));

int main(void) {
  int l, r;
  cin >> N >> M >> Q;

  for (int i = 0; i < M; i++) {
    cin >> l >> r;
    A[r][l]++;
  }

  for (int i = 1; i <= N; i++)
    for (int j = 1; j <= N; j++) {
      A[i][j] += A[i - 1][j];
      A[i][j] += A[i][j - 1];
      A[i][j] -= A[i - 1][j - 1];
    }
  for (int i = 0; i < Q; i++) {
    cin >> l >> r;
    std::cout << A[r][r] - A[r][l - 1] - A[l - 1][r] + A[l - 1][l - 1]
              << std::endl;
  }

  return 0;
}
Problem p03283 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <utility>
#include <vector>
#define INF 1e9 + 7
#define rep(i, n) for (int i = 0; i < n; i++)
#define NO cout << "NO" << endl;
#define YES cout << "YES" << endl;
#define No cout << "No" << endl;
#define Yes cout << "Yes" << endl;
#define all(a) a.begin(), a.end()
#define P pair<int, int>

//(int)'a'は97 (int)'A'は65 (int)'1'は49
// おまじない

using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

const int maxn = 500;
const int maxm = 200000;
const int maxq = 100000;

int N, M, Q;
int cnt[maxn + 1][maxn + 1] = {0};
int q_1[maxq], q_2[maxq];
int sum[maxn + 1][maxn + 1] = {0};

int main() {

  cin >> N >> M >> Q;

  rep(i, M) {
    int a, b;
    scanf("%d%d", &a, &b);
    cnt[a][b]++;
  }

  rep(i, Q) {
    scanf("%d%d", &q_1[i], &q_2[i]);
    q_1[i];
    q_2[i];
  }

  rep(i, N + 1) {
    rep(j, N + 1) { cnt[i][j + 1] += cnt[i][j]; }
  }

  rep(i, Q) {
    int res = 0;
    for (int j = q_1[i]; j <= q_2[i]; j++) {
      res += cnt[j][q_2[i]] - cnt[j][q_1[i] - 1];
    }
    printf("%d\n", res);
  }

  return 0;
}


Fixed submission:
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <utility>
#include <vector>
#define INF 1e9 + 7
#define rep(i, n) for (int i = 0; i < n; i++)
#define NO cout << "NO" << endl;
#define YES cout << "YES" << endl;
#define No cout << "No" << endl;
#define Yes cout << "Yes" << endl;
#define all(a) a.begin(), a.end()
#define P pair<int, int>

//(int)'a'は97 (int)'A'は65 (int)'1'は49
// おまじない

using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

const int maxn = 500;
const int maxm = 200000;
const int maxq = 100000;

int N, M, Q;
int cnt[maxn + 1][maxn + 1] = {0};
int q_1[maxq], q_2[maxq];
int sum[maxn + 1][maxn + 1] = {0};

int main() {

  cin >> N >> M >> Q;

  rep(i, M) {
    int a, b;
    scanf("%d%d", &a, &b);
    cnt[a][b]++;
  }

  rep(i, Q) {
    scanf("%d%d", &q_1[i], &q_2[i]);
    q_1[i];
    q_2[i];
  }

  rep(i, N + 1) {
    rep(j, N) { cnt[i][j + 1] += cnt[i][j]; }
  }

  rep(i, Q) {
    int res = 0;
    for (int j = q_1[i]; j <= q_2[i]; j++) {
      res += cnt[j][q_2[i]] - cnt[j][q_1[i] - 1];
    }
    printf("%d\n", res);
  }

  return 0;
}
Problem p03283 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int N, M, Q;
int sum[510][510];
vector<int> L(M + 10), R(M + 10), p(Q + 10), q(Q + 10);

int main() {
  cin >> N >> M >> Q;
  for (int i = 0; i < M; i++)
    cin >> L[i] >> R[i];
  for (int i = 0; i < Q; i++)
    cin >> p[i] >> q[i];
  for (int i = 0; i < M; i++) {
    sum[L[i]][R[i]]++;
  }
  for (int i = 1; i <= N; i++) {
    for (int j = 1; j <= N; j++) {
      sum[i][j] = sum[i][j] + sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1];
    }
  }
  for (int i = 0; i < Q; i++) {
    cout << sum[q[i]][q[i]] - sum[q[i]][p[i] - 1] - sum[p[i] - 1][q[i]] +
                sum[p[i] - 1][p[i] - 1]
         << endl;
  }
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int N, M, Q;
int sum[510][510];
vector<int> L(200009), R(200009), p(200009), q(200009);

int main() {
  cin >> N >> M >> Q;
  for (int i = 0; i < M; i++)
    cin >> L[i] >> R[i];
  for (int i = 0; i < Q; i++)
    cin >> p[i] >> q[i];
  for (int i = 0; i < M; i++) {
    sum[L[i]][R[i]]++;
  }
  for (int i = 1; i <= N; i++) {
    for (int j = 1; j <= N; j++) {
      sum[i][j] = sum[i][j] + sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1];
    }
  }
  for (int i = 0; i < Q; i++) {
    cout << sum[q[i]][q[i]] - sum[q[i]][p[i] - 1] - sum[p[i] - 1][q[i]] +
                sum[p[i] - 1][p[i] - 1]
         << endl;
  }
}
Problem p03283 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define forn(i, x, n) for (int i = x; i < n; i++)
#define all(a) (a).begin(), (a).end()
#define pii pair<int, int>
#define pll pair<ll, ll>
typedef long double ld;
typedef long long ll;
template <typename... Args> void dbg(Args &&...args) {
  using expander = int[];
  (void)expander{
      0,
      (static_cast<void>(void(cout << std::forward<Args>(args) << " ")), 0)...};
  cout << endl;
}
void gen() { exit(0); }
const int N = 507, M = 2e5, Q = 1e5;
int n, m, qs;
vector<int> t[N];

void input() {
  memset(t, 0, sizeof(t));
  scanf("%d %d %d", &n, &m, &qs);
  forn(i, 0, m) {
    int l, r;
    scanf(" %d %d", &l, &r);
    t[l].push_back(r);
  }
  forn(i, 1, N + 1) { sort(all(t[i])); }
}

void solve() {
  int p, q;
  forn(i, 0, qs) {
    scanf(" %d %d", &p, &q);
    int ans = 0;
    for (int j = p; j <= q; j++) {
      ans += (upper_bound(t[j].begin(), t[j].end(), q) - t[j].begin());
    }
    printf("%d\n", ans);
  }
}

int main() {
#ifdef DEBUG
  freopen("input", "r", stdin);
  // freopen("output", "w", stdout);
  // gen();
  while (!feof(stdin)) {
    input();
    solve();
    scanf(" ");
  }
#else
  input();
  solve();
#endif
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define forn(i, x, n) for (int i = x; i < n; i++)
#define all(a) (a).begin(), (a).end()
#define pii pair<int, int>
#define pll pair<ll, ll>
typedef long double ld;
typedef long long ll;
template <typename... Args> void dbg(Args &&...args) {
  using expander = int[];
  (void)expander{
      0,
      (static_cast<void>(void(cout << std::forward<Args>(args) << " ")), 0)...};
  cout << endl;
}
void gen() { exit(0); }
const int N = 507, M = 2e5, Q = 1e5;
int n, m, qs;
vector<int> t[N];

void input() {
  memset(t, 0, sizeof(t));
  scanf("%d %d %d", &n, &m, &qs);
  forn(i, 0, m) {
    int l, r;
    scanf(" %d %d", &l, &r);
    t[l].push_back(r);
  }
  forn(i, 1, N) { sort(all(t[i])); }
}

void solve() {
  int p, q;
  forn(i, 0, qs) {
    scanf(" %d %d", &p, &q);
    int ans = 0;
    for (int j = p; j <= q; j++) {
      ans += (upper_bound(t[j].begin(), t[j].end(), q) - t[j].begin());
    }
    printf("%d\n", ans);
  }
}

int main() {
#ifdef DEBUG
  freopen("input", "r", stdin);
  // freopen("output", "w", stdout);
  // gen();
  while (!feof(stdin)) {
    input();
    solve();
    scanf(" ");
  }
#else
  input();
  solve();
#endif
  return 0;
}
Problem p03283 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>

using namespace std;

const int M = 2e5;

map<int, vector<int>> mp;

pair<int, int> in[M];

int main() {
  int n, m, q;
  scanf("%d%d%d", &n, &m, &q);
  for (int i = 0; i < m; i++)
    scanf("%d%d", &in[i].first, &in[i].second);
  sort(in, in + m);
  for (int i = 0; i < m; i++)
    mp[in[i].first].push_back(in[i].second);
  while (q--) {
    int a, b, ans = 0;
    scanf("%d%d", &a, &b);
    for (int i = a; i <= b; i++) {
      ans += upper_bound(mp[i].begin(), mp[i].end(), b) - mp[i].begin();
    }
    printf("%d\n", ans);
  }
}


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

using namespace std;

const int M = 2e5;

vector<vector<int>> mp(501);

pair<int, int> in[M];

int main() {
  int n, m, q;
  scanf("%d%d%d", &n, &m, &q);
  for (int i = 0; i < m; i++)
    scanf("%d%d", &in[i].first, &in[i].second);
  sort(in, in + m);
  for (int i = 0; i < m; i++)
    mp[in[i].first].push_back(in[i].second);
  while (q--) {
    int a, b, ans = 0;
    scanf("%d%d", &a, &b);
    for (int i = a; i <= b; i++) {
      ans += upper_bound(mp[i].begin(), mp[i].end(), b) - mp[i].begin();
    }
    printf("%d\n", ans);
  }
}
Problem p03283 (C++)

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

int N, M, Q;

vector<vector<int>> sum;
int buildSumTable(vector<int> L, vector<int> R) {
  sum = vector<vector<int>>(N + 1, vector<int>(N + 1, 0));
  for (int i = 0; i < M; ++i) {
    sum[L[i]][R[i]]++;
  }

  for (int i = 0; i <= N; ++i) {
    for (int j = 1; j <= N; ++j) {
      sum[i][j] += sum[i - 1][j];
      sum[i][j] += sum[i][j - 1];
      sum[i][j] -= sum[i - 1][j - 1];
    }
  }
}

int getSumRange(int L, int R) {
  int ans = sum[R][R] - sum[R][L - 1] - sum[L - 1][R] + sum[L - 1][L - 1];
  return ans;
}

int main() {
  cin >> N >> M >> Q;
  vector<int> L(M);
  vector<int> R(M);
  for (int i = 0; i < M; ++i)
    cin >> L[i] >> R[i];
  vector<int> p(Q);
  vector<int> q(Q);
  for (int i = 0; i < Q; ++i)
    cin >> p[i] >> q[i];
  buildSumTable(L, R);
  for (int i = 0; i < Q; ++i) {
    int ans = getSumRange(p[i], q[i]);
    cout << ans << endl;
  }
}


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

int N, M, Q;

vector<vector<int>> sum;
int buildSumTable(vector<int> L, vector<int> R) {
  sum = vector<vector<int>>(N + 1, vector<int>(N + 1, 0));
  for (int i = 0; i < M; ++i) {
    sum[L[i]][R[i]]++;
  }

  for (int i = 1; i <= N; ++i) {
    for (int j = 1; j <= N; ++j) {
      sum[i][j] += sum[i - 1][j];
      sum[i][j] += sum[i][j - 1];
      sum[i][j] -= sum[i - 1][j - 1];
    }
  }
}

int getSumRange(int L, int R) {
  int ans = sum[R][R] - sum[R][L - 1] - sum[L - 1][R] + sum[L - 1][L - 1];
  return ans;
}

int main() {
  cin >> N >> M >> Q;
  vector<int> L(M);
  vector<int> R(M);
  for (int i = 0; i < M; ++i)
    cin >> L[i] >> R[i];
  vector<int> p(Q);
  vector<int> q(Q);
  for (int i = 0; i < Q; ++i)
    cin >> p[i] >> q[i];
  buildSumTable(L, R);
  for (int i = 0; i < Q; ++i) {
    int ans = getSumRange(p[i], q[i]);
    cout << ans << endl;
  }
}
Problem p03283 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ii = pair<int, int>;
#define sz(x) (int)(x).size()

const int N = 510;
const int M = 200010;
int f[N][N], g[N][N], n, m, q;
int lf[M], rt[M];

void process() {
  memset(f, 0, sizeof f);
  for (int i = 0; i < m; i++)
    f[lf[i]][rt[i]]++;
  for (int i = 1; i <= n; i++)
    g[i][i] = f[i][i];

  for (int s = 2; s <= n; s++) {
    for (int i = 1; i + s - 2 <= n; i++) {
      int j = i + s - 2;
      g[i][j] = f[i][j] + g[i + 1][j] + g[i][j - 1] - g[i + 1][j - 1];
    }
  }
  assert(g[1][n] == m);
}

int main() {
  scanf("%d%d%d", &n, &m, &q);
  for (int i = 0; i < m; i++)
    scanf("%d%d", &lf[i], &rt[i]);
  process();
  int a, b;
  for (int i = 0; i < q; i++) {
    scanf("%d%d", &a, &b);
    printf("%d\n", g[a][b]);
  }
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ii = pair<int, int>;
#define sz(x) (int)(x).size()

const int N = 510;
const int M = 200010;
int f[N][N], g[N][N], n, m, q;
int lf[M], rt[M];

void process() {
  memset(f, 0, sizeof f);
  for (int i = 0; i < m; i++)
    f[lf[i]][rt[i]]++;
  for (int i = 1; i <= n; i++)
    g[i][i] = f[i][i];

  for (int s = 2; s <= n; s++) {
    for (int i = 1; i + s - 1 <= n; i++) {
      int j = i + s - 1;
      g[i][j] = f[i][j] + g[i + 1][j] + g[i][j - 1] - g[i + 1][j - 1];
    }
  }
  assert(g[1][n] == m);
}

int main() {
  scanf("%d%d%d", &n, &m, &q);
  for (int i = 0; i < m; i++)
    scanf("%d%d", &lf[i], &rt[i]);
  process();
  int a, b;
  for (int i = 0; i < q; i++) {
    scanf("%d%d", &a, &b);
    printf("%d\n", g[a][b]);
  }
}
Problem p03283 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
int main() {
  int N, M, Q;
  cin >> N >> M >> Q;
  int A[501][501] = {0};
  int L, R;
  rep(i, M) {
    cin >> L >> R;
    A[L][R]++;
  }
  rep(i, N + 1) rep(j, N + 1) A[i][j + 1] += A[i][j];
  rep(i, N + 1) rep(j, N + 1) A[i + 1][j] += A[i][j];
  rep(i, Q) {
    int p, q;
    cin >> p >> q;
    cout << A[q][q] - A[p - 1][q] - A[q][p - 1] + A[p - 1][p - 1] << endl;
  }
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
int main() {
  int N, M, Q;
  cin >> N >> M >> Q;
  int A[510][510] = {0};
  int L, R;
  rep(i, M) {
    cin >> L >> R;
    A[L][R]++;
  }
  rep(i, N + 1) rep(j, N + 1) A[i][j + 1] += A[i][j];
  rep(i, N + 1) rep(j, N + 1) A[i + 1][j] += A[i][j];
  rep(i, Q) {
    int p, q;
    cin >> p >> q;
    cout << A[q][q] - A[p - 1][q] - A[q][p - 1] + A[p - 1][p - 1] << endl;
  }
}
Problem p03283 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define ff first
#define ss second

using namespace std;
typedef pair<int, int> pii;

vector<pii> v;
vector<int> beginnings, endings;
vector<int> seg[400200];

void build_tree(int node, int a, int b) {
  if (a == b) {
    seg[node].push_back(endings[a]);
    return;
  }
  int m = (a + b) / 2;
  build_tree(2 * node, a, m), build_tree(2 * node + 1, m + 1, b);
  merge(seg[2 * node].begin(), seg[2 * node].end(), seg[2 * node + 1].begin(),
        seg[2 * node + 1].end(), back_inserter(seg[node]));
}

int query(int node, int a, int b, int l, int r, int v) {
  if (a > r || b < l)
    return 0;
  if (l <= a && b <= r) {
    return upper_bound(seg[node].begin(), seg[node].end(), v) -
           seg[node].begin();
  }
  int m = (a + b) / 2;
  return query(2 * node, a, m, l, r, v) +
         query(2 * node + 1, m + 1, b, l, r, v);
}

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  int n, m, q, l, r, a, b;
  cin >> n >> m >> q;
  v.resize(m), beginnings.resize(m), endings.resize(m);
  for (int i = 0; i < m; ++i)
    cin >> v[i].ff >> v[i].ss;
  sort(v.begin(), v.end());
  for (int i = 0; i < m; ++i)
    beginnings[i] = v[i].ff, endings[i] = v[i].ss;
  build_tree(1, 0, m - 1);

  for (int i = 0; i < q; ++i) {
    cin >> l >> r;
    a = (lower_bound(beginnings.begin(), beginnings.end(), l) -
         beginnings.begin());
    b = (upper_bound(beginnings.begin(), beginnings.end(), r) -
         beginnings.begin()) -
        1;
    cout << query(1, 0, m - 1, a, b, r) << "\n";
  }

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define ff first
#define ss second

using namespace std;
typedef pair<int, int> pii;

vector<pii> v;
vector<int> beginnings, endings;
vector<int> seg[800200];

void build_tree(int node, int a, int b) {
  if (a == b) {
    seg[node].push_back(endings[a]);
    return;
  }
  int m = (a + b) / 2;
  build_tree(2 * node, a, m), build_tree(2 * node + 1, m + 1, b);
  merge(seg[2 * node].begin(), seg[2 * node].end(), seg[2 * node + 1].begin(),
        seg[2 * node + 1].end(), back_inserter(seg[node]));
}

int query(int node, int a, int b, int l, int r, int v) {
  if (a > r || b < l)
    return 0;
  if (l <= a && b <= r) {
    return upper_bound(seg[node].begin(), seg[node].end(), v) -
           seg[node].begin();
  }
  int m = (a + b) / 2;
  return query(2 * node, a, m, l, r, v) +
         query(2 * node + 1, m + 1, b, l, r, v);
}

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  int n, m, q, l, r, a, b;
  cin >> n >> m >> q;
  v.resize(m), beginnings.resize(m), endings.resize(m);
  for (int i = 0; i < m; ++i)
    cin >> v[i].ff >> v[i].ss;
  sort(v.begin(), v.end());
  for (int i = 0; i < m; ++i)
    beginnings[i] = v[i].ff, endings[i] = v[i].ss;
  build_tree(1, 0, m - 1);

  for (int i = 0; i < q; ++i) {
    cin >> l >> r;
    a = (lower_bound(beginnings.begin(), beginnings.end(), l) -
         beginnings.begin());
    b = (upper_bound(beginnings.begin(), beginnings.end(), r) -
         beginnings.begin()) -
        1;
    cout << query(1, 0, m - 1, a, b, r) << "\n";
  }

  return 0;
}
Problem p03283 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
#include <vector>

using namespace std;

int main() {
  int i = 0;
  int counter1 = 0, counter2 = 0;
  int tmp1 = 0, tmp2 = 0;
  int cap_num = 0, train_num = 0, question_num = 0;
  char map[500][500] = {{0}};
  cin >> cap_num >> train_num >> question_num;
  for (i = 0; i < train_num; ++i) {
    cin >> tmp1 >> tmp2;
    map[tmp1][tmp2]++;
  }
  for (i = 0; i <= cap_num; ++i) {
    for (counter1 = 1; counter1 <= cap_num; ++counter1) {
      map[counter1][i] += map[counter1 - 1][i];
    }
  }
  for (i = 0; i < question_num; ++i) {
    cap_num = 0;
    cin >> tmp1 >> tmp2;
    for (counter1 = tmp1; counter1 <= tmp2; ++counter1) {
      cap_num += map[tmp2][counter1] - map[tmp1 - 1][counter1];
    }
    cout << cap_num << endl;
  }
  return 0;
}

Fixed submission:
#include <iostream>
#include <vector>

using namespace std;

int main() {
  int i = 0;
  int counter1 = 0, counter2 = 0;
  int tmp1 = 0, tmp2 = 0;
  int cap_num = 0, train_num = 0, question_num = 0;
  int map[501][501] = {{0}};
  cin >> cap_num >> train_num >> question_num;
  for (i = 0; i < train_num; ++i) {
    cin >> tmp1 >> tmp2;
    map[tmp1][tmp2]++;
  }
  for (i = 0; i <= cap_num; ++i) {
    for (counter1 = 1; counter1 <= cap_num; ++counter1) {
      map[counter1][i] += map[counter1 - 1][i];
    }
  }
  for (i = 0; i < question_num; ++i) {
    cap_num = 0;
    cin >> tmp1 >> tmp2;
    for (counter1 = tmp1; counter1 <= tmp2; ++counter1) {
      cap_num += map[tmp2][counter1] - map[tmp1 - 1][counter1];
    }
    cout << cap_num << endl;
  }
  return 0;
}
Problem p03283 (C++)

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

using ll = long long;
#define ALL(c) (c).begin(), (c).end()
const int MOD = 1000000007;

int main() {
  int n, m, q;
  cin >> n >> m >> q;
  vector<vector<int>> v(n + 1, vector<int>(n + 1, 0));

  int l, r;
  for (int i = 0; i < m; i++) {
    cin >> l >> r;
    for (int j = 1; j <= l; j++) {
      for (int k = r; k <= n; k++) {
        v[j][k]++;
      }
    }
  }
  int p, o;
  for (int i = 0; i < q; i++) {
    cin >> p >> o;
    cout << v[p][o] << endl;
  }
}


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

using ll = long long;
#define ALL(c) (c).begin(), (c).end()
const int MOD = 1000000007;

int main() {
  int n, m, q;
  cin >> n >> m >> q;
  vector<vector<int>> v(n + 1, vector<int>(n + 1, 0));

  int l, r;
  for (int i = 0; i < m; i++) {
    cin >> l >> r;
    for (int j = 1; j <= l; j++) {
      v[j][r]++;
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      v[i][j] += v[i][j - 1];
    }
  }
  int p, o;
  for (int i = 0; i < q; i++) {
    cin >> p >> o;
    cout << v[p][o] << endl;
  }
}