Problem p03283 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define MOD 1000000007
#define ll long long
#define ld long double
#define slld(t) scanf("%lld", &t)
#define sd(t) scanf("%d", &t)
#define sc(x) scanf("%s", x)
#define pd(t) printf("%d\n", t)
#define plld(t) printf("%lld\n", t)
#define mp(a, b) make_pair(a, b)
#define pii pair<int, int>
#define pli pair<ll, int>
#define pil pair<int, ll>
#define pll pair<ll, ll>
#define ff first
#define ss second
#define pb(x) push_back(x)
#define ub upper_bound
#define lb lower_bound
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
#define clr(x) memset(x, 0, sizeof(x))
#define sws                                                                    \
  ios::sync_with_stdio(false);                                                 \
  cin.tie(0);                                                                  \
  cout.tie(0)
#define pi acos(-1)
#define rep(I, N) for (ll I = 0; I < (N); ++I)
#define repp(I, a, B) for (ll I = (a); I <= (B); ++I)
#define t1(x) cout << #x << ": " << x << endl
#define t2(x, y) cout << #x << ": " << x << " | " << #y << ": " << y << endl
#define t3(x, y, z)                                                            \
  cout << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": "   \
       << z << endl
#define t4(a, b, c, d)                                                         \
  cout << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": "   \
       << c << " | " << #d << ": " << d << endl
#define t5(a, b, c, d, e)                                                      \
  cout << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": "   \
       << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl
#define t6(a, b, c, d, e, f)                                                   \
  cout << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": "   \
       << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | "   \
       << #f << ": " << f << endl
using namespace std;
int months[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
string itos(ll i) {
  string s = "";
  while (i) {
    s += char(i % 10 + '0');
    i /= 10;
  }
  reverse(all(s));
  return s;
}
ll stoi(string &s) {
  ll tot = 0;
  for (int i = (int)s.length() - 1, j = 1; i >= 0; i--, j *= 10) {
    tot += j * (s[i] + '0');
  }
  return tot;
}
bool cmp(const pair<int, int> &a, const pair<int, int> &b) {
  return (a.first > b.first);
}
/*const int maxn = 2e5 + 5;
ll fact[maxn];
ll invfact[maxn];
ll C(ll n, ll k)
{
    return fact[n] * 1ll * invfact[n - k] % MOD * invfact[k] % MOD;
}
void Combpre()
{
    fact[0] = 1;
    for (long long i = 1; i < N; ++i)
    {
        fact[i] = 1ll * i * fact[i - 1] ;
    }
    // for inverse MODulo : if (1/b)%MOD then ans is (b^(MOD-2))%MOD
    invfact[N - 1] = pwr(fact[N - 1], MOD - 2, MOD);
    for (long long i = N - 2; i >= 0; --i)
    {
        invfact[i] = 1ll * invfact[i + 1] * (i + 1) % MOD;
    }
}
inline int add(int a,int b)
{
    a = a + b;
    if(a>=MOD)a -= MOD;
    return a;
}
inline int sub(int a,int b)
{
    a = a - b;
    if(a < 0)a += MOD;
    return a;
}
inline int mul(ll a,ll b)
{
    a = a * b % MOD;
    return a;
}*/
/*const int MaX = 2e6 + 5;
bool isPrime[MaX];
void sieve(int n)
{
    for(int i = 0; i <= n;++i)
    {
        isPrime[i] = true;
    }
    isPrime[0] = false;
    isPrime[1] = false;
    for(int i = 2; i * i <= n; ++i)
    {
         if(isPrime[i] == true)
         {
             for(int j = i * i; j <= n ;j += i)
                 isPrime[j] = false;
        }
    }
}*/
ll pwr(ll base, ll p, ll mod = MOD) {
  ll ans = 1;
  while (p) {
    if (p & 1)
      ans = (ans * base) % MOD;
    base = (base * base) % MOD;
    p /= 2;
  }
  return ans;
}
ll gcd(ll a, ll b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
  return (a * b * 1LL) / gcd(a, b);
  /* LCM for big numbers
  if(max(a,b) % min(a,b) == 0) LCM = max(a,b);
  else { LCM = lcm(a,b);if(LCM % w == 0 && LCM % b == 0) f = 1;
      if(!f || LCM < 0) LCM overflows}*/
}

const int N = 2e5 + 5;
const int LN = 30;

int n, m, q;
vector<int> s[101];

int main() {
  sws;
  srand(time(NULL));
  cout << fixed << setprecision(10);
  clock_t clk;
  clk = clock();

  // freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);

  cin >> n >> m >> q;
  int l, r;
  repp(i, 1, m) {
    cin >> l >> r;
    s[l].pb(r);
  }
  for (int i = 1; i <= n; i++)
    sort(all(s[i]));
  repp(i, 1, q) {
    cin >> l >> r;
    int ans = 0;
    repp(i, l, r) {
      auto it = upper_bound(s[i].begin(), s[i].end(), r);
      int cnt = it - s[i].begin();
      ans += cnt;
    }
    cout << ans << "\n";
  }

  clk = clock() - clk;
  cerr << fixed << setprecision(6) << "Time: " << ((double)clk) / CLOCKS_PER_SEC
       << "\n";

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define MOD 1000000007
#define ll long long
#define ld long double
#define slld(t) scanf("%lld", &t)
#define sd(t) scanf("%d", &t)
#define sc(x) scanf("%s", x)
#define pd(t) printf("%d\n", t)
#define plld(t) printf("%lld\n", t)
#define mp(a, b) make_pair(a, b)
#define pii pair<int, int>
#define pli pair<ll, int>
#define pil pair<int, ll>
#define pll pair<ll, ll>
#define ff first
#define ss second
#define pb(x) push_back(x)
#define ub upper_bound
#define lb lower_bound
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
#define clr(x) memset(x, 0, sizeof(x))
#define sws                                                                    \
  ios::sync_with_stdio(false);                                                 \
  cin.tie(0);                                                                  \
  cout.tie(0)
#define pi acos(-1)
#define rep(I, N) for (ll I = 0; I < (N); ++I)
#define repp(I, a, B) for (ll I = (a); I <= (B); ++I)
#define t1(x) cout << #x << ": " << x << endl
#define t2(x, y) cout << #x << ": " << x << " | " << #y << ": " << y << endl
#define t3(x, y, z)                                                            \
  cout << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": "   \
       << z << endl
#define t4(a, b, c, d)                                                         \
  cout << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": "   \
       << c << " | " << #d << ": " << d << endl
#define t5(a, b, c, d, e)                                                      \
  cout << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": "   \
       << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl
#define t6(a, b, c, d, e, f)                                                   \
  cout << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": "   \
       << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | "   \
       << #f << ": " << f << endl
using namespace std;
int months[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
string itos(ll i) {
  string s = "";
  while (i) {
    s += char(i % 10 + '0');
    i /= 10;
  }
  reverse(all(s));
  return s;
}
ll stoi(string &s) {
  ll tot = 0;
  for (int i = (int)s.length() - 1, j = 1; i >= 0; i--, j *= 10) {
    tot += j * (s[i] + '0');
  }
  return tot;
}
bool cmp(const pair<int, int> &a, const pair<int, int> &b) {
  return (a.first > b.first);
}
/*const int maxn = 2e5 + 5;
ll fact[maxn];
ll invfact[maxn];
ll C(ll n, ll k)
{
    return fact[n] * 1ll * invfact[n - k] % MOD * invfact[k] % MOD;
}
void Combpre()
{
    fact[0] = 1;
    for (long long i = 1; i < N; ++i)
    {
        fact[i] = 1ll * i * fact[i - 1] ;
    }
    // for inverse MODulo : if (1/b)%MOD then ans is (b^(MOD-2))%MOD
    invfact[N - 1] = pwr(fact[N - 1], MOD - 2, MOD);
    for (long long i = N - 2; i >= 0; --i)
    {
        invfact[i] = 1ll * invfact[i + 1] * (i + 1) % MOD;
    }
}
inline int add(int a,int b)
{
    a = a + b;
    if(a>=MOD)a -= MOD;
    return a;
}
inline int sub(int a,int b)
{
    a = a - b;
    if(a < 0)a += MOD;
    return a;
}
inline int mul(ll a,ll b)
{
    a = a * b % MOD;
    return a;
}*/
/*const int MaX = 2e6 + 5;
bool isPrime[MaX];
void sieve(int n)
{
    for(int i = 0; i <= n;++i)
    {
        isPrime[i] = true;
    }
    isPrime[0] = false;
    isPrime[1] = false;
    for(int i = 2; i * i <= n; ++i)
    {
         if(isPrime[i] == true)
         {
             for(int j = i * i; j <= n ;j += i)
                 isPrime[j] = false;
        }
    }
}*/
ll pwr(ll base, ll p, ll mod = MOD) {
  ll ans = 1;
  while (p) {
    if (p & 1)
      ans = (ans * base) % MOD;
    base = (base * base) % MOD;
    p /= 2;
  }
  return ans;
}
ll gcd(ll a, ll b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
  return (a * b * 1LL) / gcd(a, b);
  /* LCM for big numbers
  if(max(a,b) % min(a,b) == 0) LCM = max(a,b);
  else { LCM = lcm(a,b);if(LCM % w == 0 && LCM % b == 0) f = 1;
      if(!f || LCM < 0) LCM overflows}*/
}

const int N = 2e5 + 5;
const int LN = 30;

int n, m, q;
vector<int> s[501];

int main() {
  sws;
  srand(time(NULL));
  cout << fixed << setprecision(10);
  clock_t clk;
  clk = clock();

  // freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);

  cin >> n >> m >> q;
  int l, r;
  repp(i, 1, m) {
    cin >> l >> r;
    s[l].pb(r);
  }
  for (int i = 1; i <= n; i++)
    sort(all(s[i]));
  repp(i, 1, q) {
    cin >> l >> r;
    int ans = 0;
    repp(i, l, r) {
      auto it = upper_bound(s[i].begin(), s[i].end(), r);
      int cnt = it - s[i].begin();
      ans += cnt;
    }
    cout << ans << "\n";
  }

  clk = clock() - clk;
  cerr << fixed << setprecision(6) << "Time: " << ((double)clk) / CLOCKS_PER_SEC
       << "\n";

  return 0;
}