Problem:
 Score: 400 points    Problem Statement  In Takahashi Kingdom, there is a east-west railroad and N cities along it, numbered 1 , 2 , 3 , ..., N from west to east.
A company called AtCoder Express possesses M trains, and the train i runs from City L_i to City R_i (it is possible that L_i = R_i ).
Takahashi the king is interested in the following Q matters:   The number of the trains that runs strictly within the section from City p_i to City q_i , that is, the number of trains j such that p_i \leq L_j and R_j \leq q_i .   Although he is genius, this is too much data to process by himself. Find the answer for each of these Q queries to help him.      Constraints   N is an integer between 1 and 500 (inclusive).  M is an integer between 1 and 200 \ 000 (inclusive).  Q is an integer between 1 and 100 \ 000 (inclusive).  1 \leq L_i \leq R_i \leq N  (1 \leq i \leq M)  1 \leq p_i \leq q_i \leq N  (1 \leq i \leq Q)         Input  Input is given from Standard Input in the following format:  N  M  Q  L_1  R_1  L_2  R_2  :  L_M  R_M  p_1  q_1  p_2  q_2  :  p_Q  q_Q       Output  Print Q lines. The i -th line should contain the number of the trains that runs strictly within the section from City p_i to City q_i .        Sample Input 1 2 3 1
1 1
1 2
2 2
1 2      Sample Output 1 3  As all the trains runs within the section from City 1 to City 2 , the answer to the only query is 3 .       Sample Input 2 10 3 2
1 5
2 8
7 10
1 7
3 10      Sample Output 2 1
1  The first query is on the section from City 1 to 7 . There is only one train that runs strictly within that section: Train 1 .
The second query is on the section from City 3 to 10 . There is only one train that runs strictly within that section: Train 3 .       Sample Input 3 10 10 10
1 6
2 9
4 5
4 7
4 7
5 8
6 6
6 7
7 9
10 10
1 8
1 9
1 10
2 8
2 9
2 10
3 8
3 9
3 10
1 10      Sample Output 3 7
9
10
6
8
9
6
7
8
10

Solution (Python):
n, m, q = map(int, input().split())

x = [[0 for i in range(n)] for j in range(n)]

for i in range(m):
    a, b = map(int, input().split())
    x[a-1][b-1] += 1

for j in range(1, n):
    for k in range(n-j):
        x[k][j+k] += x[k][j+k-1] + x[k+1][j+k] - x[k+1][j+k-1]

for i in range(q):
    a, b = map(int, input().split())
    print(x[a-1][b-1])

Solution (Python):

import sys

N, M, Q = map(int, sys.stdin.readline().strip().split())

cusum = [[0] * (N + 1) for _ in range(N + 1)]
for _ in range(M):
    L, R = map(int, sys.stdin.readline().strip().split())
    cusum[L][R] += 1


for i in range(N):
    for j in range(N):
        cusum[i + 1][j + 1] += cusum[i + 1][j] + cusum[i][j + 1] - cusum[i][j]


for _ in range(Q):
    p, q = map(int, sys.stdin.readline().strip().split())  

    ans = cusum[q][q] - cusum[q][p - 1] - cusum[p - 1][q] + cusum[p- 1][p - 1]
    print(ans)

Solution (Python):
N, M, Q = map(int, input().split())
trains = [[0] * (N + 1) for _ in range(N + 1)]
for _ in range(M):
    L, R = map(int, input().split())
    trains[L][R] += 1
for i in range(1, N + 1):
    for j in range(1, N + 1):
        trains[i][j] += trains[i - 1][j]
for i in range(1, N + 1):
    for j in range(1, N + 1):
        trains[i][j] += trains[i][j - 1]
ans = [0] * Q
for k in range(Q):
    p, q = map(int, input().split())
    ans[k] = trains[q][q] - trains[p-1][q] - trains[q][p-1] + trains[p-1][p-1]
for A in ans:
    print(A)

Solution (Python):
def main():
    import sys
    import numpy as np
    ikimasu = sys.stdin.buffer.readline
    ini = lambda: int(ins())
    ina = lambda: list(map(int, ikimasu().split()))
    ins = lambda: ikimasu().strip()
    
    n,m,q = ina()
    tmp = [[0]*(n+1) for _ in range(n+1)]
    for _ in range(m):
        l,r = ina()
        tmp[l][r]+=1


    tmp = np.cumsum(tmp,axis=1).cumsum(axis = 0)

    for _ in range(q):
        p,q = ina()
        rick = tmp[q][q]+tmp[p-1][p-1]-tmp[p-1][q]-tmp[q][p-1]
        print(rick)
        


    
        


        


    




















if __name__ == "__main__":
    main()

Solution (Python):
ma = lambda :map(int,input().split())
lma = lambda :list(map(int,input().split()))
tma = lambda :tuple(map(int,input().split()))
ni = lambda:int(input())
yn = lambda fl:print("Yes") if fl else print("No")
ips = lambda:input().split()
import collections
import math
import itertools
import heapq as hq
n,m,q = ma()
L_rs=[[] for i in range(n)]
for i in range(m):
    l,r=ma()
    L_rs[l-1].append(r-1)
for i in range(n):
    L_rs[i].sort()

def isok(num,val):
    return num<=val
def bisect(ls,val): 
    ok = -1
    ng = len(ls)
    x = (ok+ng)//2
    while ng-ok>1:
        num = ls[x]
        if isok(num,val):
            ok = x
        else:
            ng = x
        x = (ok+ng)//2
    return ok 

ans = [[0]*(n+1) for i in range(n+1)]
for r in range(n):
    for l in range(r,-1,-1):
        ans[l][r]=ans[l+1][r] + bisect(L_rs[l],r)+1

for i in range(q):
    l,r=ma()
    print(ans[l-1][r-1])

Solution (Python):
import numpy as np
N,M,Q=map(int, input().split())
a=np.array([[0]*(N+1) for i in range(N+1)])
for i in range(M):
  l,r=map(int, input().split())
  a[l][r]+=1
a=a.cumsum(axis=0).cumsum(axis=1)
for i in range(Q):
  p,q=map(int, input().split())
  print(a[q][q]-a[p-1][q]-a[q][p-1]+a[p-1][p-1])

Solution (Python):
import numpy as np
N,M,Q=map(int, input().split())
a=np.array([[0]*(N+1) for i in range(N+1)])
for i in range(M):
  l,r=map(int, input().split())
  a[l][r]+=1
a=a.cumsum(axis=0).cumsum(axis=1)
for i in range(Q):
  p,q=map(int, input().split())
  print(a[q][q]-a[p-1][q])

Solution (Python):




def solve():
    N, M, Q = map(int, input().split())
    LR_L = tuple([int(x) for x in input().split()] for y in range(M))
    Q_L = tuple([int(x) for x in input().split()] for y in range(Q))

    imos_l = [[0] * (N+2) for _ in range(N+1)]

    for l, r in LR_L:
        imos_l[l][l] += 1
        imos_l[l][r+1] -= 1
    for i in range(1, N+1):
        for j in range(1, N+2):
            imos_l[i][j] += imos_l[i][j-1]

    for p, q in Q_L:
        ans = 0
        for i in range(p, q+1):
            ans += imos_l[i][i] - imos_l[i][q+1]
        print(ans)


solve()

Solution (Python):
n,m,q=map(int,input().split())
import numpy as np
dim2=np.zeros((n+1,n+1),dtype='int8')

for _ in range(m):
    l,r=map(int,input().split())
    dim2[l][r]+=1

dim2=np.cumsum(dim2,axis=0)

dim2=np.cumsum(dim2,axis=1)
for _ in range(q):
    p,q=map(int, input().split())
    ans=dim2[q][q]-dim2[q][p-1]-dim2[p-1][q]+dim2[p-1][p-1]
    print(ans)

Solution (Python):
N, M, Q = map(int,input().split())

cnt = [[0]*(N+1) for _ in range(N+1)]
for _ in range(M):
    L, R = map(int,input().split())
    cnt[L][R] += 1

for i in range(N):
    for j in range(N):
        cnt[i+1][j+1] += cnt[i+1][j] + cnt[i][j+1] - cnt[i][j]

for _ in range(Q):
    p, q = map(int,input().split())
    print(cnt[q][q] - cnt[q][p-1] - cnt[p-1][q] + cnt[p-1][p-1])

Solution (Python):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time, copy,bisect
from operator import itemgetter





sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

stdin = sys.stdin

ni = lambda: int(ns())
nf = lambda: float(ns())
na = lambda: list(map(int, stdin.readline().split()))
nb = lambda: list(map(float, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  

N, M, Q = na()
dp = [[0] * (N + 3) for _ in range(N + 3)]
for i in range(M):
    l, r = na()
    dp[1][r] += 1
    dp[l+1][r] -= 1
    dp[l][N+1] -= 1

for i in range(N+1):
    for j in range(N+1):
        dp[i][j+1] += dp[i][j]

for j in range(N+1):
    for i in range(N+1):
        dp[i+1][j] += dp[i][j]

for i in range(Q):
    p, q = na()
    print(dp[p][q])

Solution (Python):
n, m, q = map(int, input().split())
lr = []
for _ in range(m):
    lr.append(list(map(int, input().split())))

a = [[0] * n for i in range(n)]
for l, r in lr:
    a[l - 1][r - 1] += 1

cnt = [[0]*n for i in range(n)]
for y in range(n):
    v = 0
    for x in range(y, -1, -1):
        v += a[x][y]
        cnt[x][y] = cnt[x][y - 1] + v

for _ in range(q):
    p, q = map(int, input().split())
    print(cnt[p-1][q-1])

Solution (Python):
import sys
input = sys.stdin.readline

N, M, Q = map(int, input().split())
cum = [[0]*(N+1) for _ in range(N+1)]
for _ in range(M):
    l, r = map(int, input().split())
    cum[l][r] += 1
for i in range(1, N+1):
    for j in range(i+1, N+1):
        cum[i][j] += cum[i][j-1]
ans = []
for _ in range(Q):
    p, q = map(int, input().split())
    tot = 0
    for i in range(p, q+1):
        tot += cum[i][q]
    ans.append(tot)
print(*ans, sep="\n")

Solution (Python):
import sys
input = sys.stdin.readline

N, M, Q = map(int, input().split())
cum = [[0]*(N+1) for _ in range(N+1)]
for _ in range(M):
    l, r = map(int, input().split())
    cum[l][r] += 1
for i in range(1, N+1):
    for j in range(i+1, N+1):
        cum[i][j] += cum[i][j-1]
for _ in range(Q):
    p, q = map(int, input().split())
    tot = 0
    for i in range(p, q+1):
        tot += cum[i][q]
    print(tot)

Solution (Python):
import sys
input = sys.stdin.readline

N, M, Q = map(int, input().split())
cum = [[0]*(N+1) for _ in range(N+1)]
for _ in range(M):
    l, r = map(int, input().split())
    cum[l][r] += 1
for i in range(1, N+1):
    for j in range(i+1, N+1):
        cum[i][j] = cum[i][j] + cum[i][j-1]
ans = []
for _ in range(Q):
    p, q = map(int, input().split())
    tot = 0
    for i in range(p, q+1):
        tot += cum[i][q]
    ans.append(tot)
print(*ans, sep="\n")

Solution (Python):
def main():
    N, M, Q = map(int, input().split())
    A = [[0] * (N + 1) for _ in range(N + 1)]
    for _ in range(M):
        L, R = map(int, input().split())
        A[L][R] += 1
    
    S = [[0] * (N + 2) for _ in range(N + 2)]
    for i in range(N+1):
        for j in range(N+1):
            S[i+1][j+1] = S[i][j+1] + S[i+1][j] - S[i][j] + A[i][j]
    for _ in range(Q):
        p, q = map(int, input().split())
        ans = S[q+1][q+1] - S[p][q+1] - S[q+1][p] + S[p][p]
        print(ans)

if __name__ == "__main__":
    main()

Solution (Python):
import sys
def input():
    return sys.stdin.readline()[:-1]
def make_sumtable():
    sumtable = [[0]*(N+1) for i in range(N+1)]
    for i in range(M):
        sumtable[L[i]][R[i]] += 1
    for i in range(1,N+1):
        for j in range(1,N+1):
            sumtable[i][j] += sumtable[i-1][j]
            sumtable[i][j] += sumtable[i][j-1]
            sumtable[i][j] -= sumtable[i-1][j-1]
    return sumtable
N,M,Q = map(int,input().split())

L = []
R = []
for i in range(M):
    l,r = map(int,input().split())
    L.append(l)
    R.append(r)

sumtable = make_sumtable()

for i in range(Q):
    p,q = map(int,input().split())
    print(sumtable[q][q]-sumtable[q][p-1]-sumtable[p-1][q]+sumtable[p-1][p-1])

Solution (Python):
n, m, q = map(int, input().split())
start_goal = [[0]*n for _ in range(n)]
for _ in range(m):
    l, r = map(int, input().split())
    l -= 1
    r -= 1
    start_goal[l][r] += 1



s_2 = [[0]*(n+1) for _ in range(n+1)]
for i in range(n):
    for j in range(n):
        s_2[i+1][j+1] = s_2[i][j+1] + s_2[i+1][j] - s_2[i][j] + start_goal[i][j]


for _ in range(q):
    l, r = map(int, input().split())
    ans = s_2[n][r] - s_2[l-1][r]
    print(ans)

Solution (Python):
import numpy as np 
N,M,Q=map(int, input().split())
a=np.array([[0]*N for i in range(N)])

for i in range(M):
  l,r=map(int, input().split())
  a[l-1][r-1]+=1
a=a.cumsum(axis=0).cumsum(axis=1)

for i in range(Q):
  p,q=map(int, input().split())
  if p==1:
    ans=a[q-1][q-1]
  else:
    ans=a[q-1][q-1]-a[p-2][q-1]
  print(ans)

Solution (Python):
n, m, q = map(int, input().split())
lr = []
for _ in range(m):
    l, r = map(int, input().split())
    lr.append((l, r))
query = []
for _ in range(q):
    p, q = map(int, input().split())
    query.append((p, q))
accu = [[0]*(n+1) for _ in range(n+1)]
for l, r in lr:
    accu[l][r] += 1
for i in range(n):
    for j in range(n):
        accu[i+1][j+1] += accu[i+1][j]
for j in range(n):
    for i in range(n):
        accu[i+1][j+1] += accu[i][j+1]
ans = []
for p, q in query:
    ans.append(accu[q][q]-accu[q][p-1]-accu[p-1][q]+accu[p-1][p-1])
print(*ans, sep='\n')