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):
import sys
from itertools import accumulate
N, M, Q = [int(i) for i in input().strip().split(' ')]

flag  = False
counter = M

d = []
d2 = []
for i in range(N):
    d.append([0] * N)
for i in range(N):
    d2.append([0] * N)


for line in sys.stdin:
    L, R = [int(i) for i in line.strip().split(' ')]
    if not flag:
        d[L-1][R-1] += 1



        counter -= 1
        if counter == 0:

            for i in range(N):
                d[i] = d[i][::-1]

            for i in range(N):
                if i == 0:
                    d[N-1] = list(accumulate(d[N-1][::-1]))[::-1]
                else:
                    for j in range(N):
                        if j == 0:
                            temp = d[N-1-i][N-1-j]
                        else:
                            temp += d[N-1-i][N-1-j]
                        d[N-1-i][N-1-j] = d[N-i][N-1-j] + temp



            flag = True
    else:
        print(d[L-1][N-R])

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


Query=[]
answer=[[0]*N for i in range(N)]
for i in range(M):
  L,R=map(int,input().split())
  answer[N-L][R-1]+=1

for i in range(1,N):
  answer[0][i]+=answer[0][i-1]
  answer[i][0]+=answer[i-1][0]
  
for i in range(1,N):
  for j in range(1,N):
    answer[i][j]+=answer[i-1][j]
    answer[i][j]+=answer[i][j-1]
    answer[i][j]-=answer[i-1][j-1]
for i in range(Q):
  p,q=map(int,input().split())
  print(answer[N-p][q-1])
'''
for i in range(Q):
  answer=0
  Query=list(map(int,input().split()))
  for j in range(M):
    if train[j][0]>=Query[0] and train[j][1]<=Query[1]:
      answer+=1
  print(answer)
'''

Solution (Python):
import numpy as np

N, M, Q = list(map(int, input().split()))

a = np.zeros((N+1, N+1), dtype=np.int)

for i in range(M):
    L, R = list(map(int, input().split()))
    a[N-L, R] += 1

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

for i in range(Q):
    p, q = list(map(int, input().split()))
    print(a[N-p, q])

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

ns = [[0 for _ in range(n + 1)]for _ in range(n + 1)]

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

for i in range(1, n + 1):
    for j in range(i, n + 1):
        ns[i][j] += ns[i][j - 1]
for j in range(1, n + 1):
    for i in range(1, j + 1):
        ns[i][j] += ns[i - 1][j]

for i in range(q):
    count = 0
    (l, r) = map(int, input().split(" "))
    print(ns[r][r] - ns[l - 1][r])

Solution (Python):
N, M, Q = map(int, raw_input().split())
L = []
R = []
for i in range(M):
	_l, _r = map(int, raw_input().split())
	L.append(_l)
	R.append(_r)

p = []
q = []
for i in range(Q):
	_p, _q = map(int, raw_input().split())
	p.append(_p)
	q.append(_q)


start_end_mat = [[0] * (N + 1) for i in range(N + 1)]

for i in range(M):
	start_end_mat[L[i]][R[i]] += 1

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

for i in range(Q):
	res = start_end_mat[N][q[i]]
	res -= start_end_mat[p[i] - 1][q[i]]
	print(res)

Solution (Python):



import bisect
import array


def solve():
    n, m, q = map(int, input().split())
    nl = [[0 for i in range(n + 1)] for j in range(n + 1)]
    for e in [input().split() for _ in range(m)]:
        l, r = int(e[0]), int(e[1])
        nl[l][r] += 1
    table = [array.array("i", [0] * (n + 2)) for j in range(n + 2)]
    ran = array.array("i", range(n + 1))
    for i in ran:
        for j in ran:
            table[i][j + 1] = table[i][j] + nl[i][j]

    for i, e in enumerate([input().split() for _ in range(q)]):
        l, r = int(e[0]), int(e[1])
        ans = 0
        for j in range(l, r + 1):
            ans += table[j][r + 1] - table[j][l]
        print(ans)


if __name__ == "__main__":
    solve()

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

N_LR = [[0 for i in range(N+1)] for j in range(N+1)]

for i in range(M):
  l, r = map(int, input().split() )
  N_LR[l][r] += 1


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

for i in range(Q):
  x,y = map(int, input().split() )
  ans = N_LR[y][y] - N_LR[x-1][y] - N_LR[y][x-1] + N_LR[x-1][x-1]
  print(ans)

Solution (Python):
N,M,Q=map(int,input().split())
table=[[0]*(N+1) for i in range(N+1)]
ans=[]
for i in range(M):
    l,m=map(int,input().split())
    table[l][m]+=1
for i in range(Q):
    l,m=map(int,input().split())
    ans.append((l,m))

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

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

for l,m in ans:
    print(table[m][m]-table[l-1][m]-table[m][l-1]+table[l-1][l-1])

Solution (Python):
import numpy as np
n, m, q = [int(item) for item in input().split(" ")]


end = np.zeros((m,2),dtype=int)
query = np.zeros((q,2),dtype=int)
for i in range(m):
    end[i] = [int(item) for item in input().split(" ")]


for i in range(q):
    query[i] = [int(item) for item in input().split(" ")]


a = np.zeros((n,n), dtype=int)
np.add.at(a, [end[:,0]-1,end[:,1]-1], 1)
b = np.cumsum(a[::-1,:], axis=0)[::-1,:]
c = np.cumsum(b, axis=1)
for item in query:
    print(c[item[0]-1, item[1]-1])

Solution (Python):
N, M, Q = map(int,input().split())
m =  [[0 for y in range(N+1)] for x in range(N+1)]
m2 =  [[0 for y in range(N+1)] for x in range(N+1)]
m3 =[[0 for y in range(N+1)] for x in range(N+1)]

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

for j in range(1, N+1):
    s=0
    for i in range(1, N+1):
        s+=m[i][j]
        m2[i][j]=s

for i in range(1, N+1):
    s=0
    for j in range(i, N+1):
        s+=m2[j][j]-m2[i-1][j]
        m3[i][j]=s

for i in range(1,Q+1):
    l, r = map(int,input().split())
    print(m3[l][r])

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

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


class CumSum2d(object):
    def __init__(self, H, W):
        self.H, self.W = H, W
        self.tiles = [[0] * W for _ in range(H)]

    def add(self, x, y, c=1):
        self.tiles[y][x] += c

    def build(self):
        for y in range(self.H):
            for x in range(1, self.W):
                self.tiles[y][x] += self.tiles[y][x - 1]
        for y in range(1, self.H):
            for x in range(self.W):
                self.tiles[y][x] += self.tiles[y - 1][x]

    def get(self, sx, sy, tx, ty):
        assert sx <= tx and sy <= ty
        cnt = self.tiles[ty][tx]
        if sx > 0:
            cnt -= self.tiles[ty][sx - 1]
        if sy > 0:
            cnt -= self.tiles[sy - 1][tx]
        if sx > 0 and sy > 0:
            cnt += self.tiles[sy - 1][sx - 1]
        return cnt


cs = CumSum2d(N, N)
for i in range(M):
    l, r = map(int, input().split())
    cs.add(l - 1, r - 1)
cs.build()

for _ in range(Q):
    p, q = map(int, input().split())
    ans = cs.get(p - 1, p - 1, q - 1, q - 1)
    print(ans)

Solution (Python):
N, M, Q = map(int, input().split())
tbl = [[0] * (N + 1) for _ in range(N)]

for _ in range(M):
    l, r = [int(x) - 1 for x in input().split()]
    tbl[l][r] += 1

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

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

for _ in range(Q):
    p, q = [int(x) - 1 for x in input().split()]
    if p == 0:
        print(tbl[q][q])
    else:
        print(tbl[q][q] - tbl[p - 1][q] - tbl[q][p - 1] + tbl[p - 1][p - 1])

Solution (Python):
import numpy as np

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

mat = np.zeros((n, n), dtype=int)

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

ans = np.cumsum(np.cumsum(mat, axis=1)[::-1], axis=0)[::-1]

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

Solution (Python):
from numpy import cumsum 
n, m, q = list(map(int, input().split()))
lst = [[0]*(n+1) for i in range(n+1)]
for i in range(m):
    l, r = list(map(int, input().split()))
    lst[l][r] += 1
ans1 = cumsum(lst, axis=1)
ans = cumsum(ans1, axis=0)
for i in range(q):
    a, b = list(map(int, input().split()))
    print(ans[b, b] - ans[a-1, b])

Solution (Python):


import sys


def main():
    n, m, q = [int(x) for x in sys.stdin.readline().rstrip().split(' ')]

    x = [[0 for j in range(n+1)] for i in range(n+1)]
    c = [[0 for j in range(n+1)] for i in range(n+1)]
    z = [[0 for j in range(n+1)] for i in range(n+1)]

    for i in range(m):
        l, r = [int(x) for x in sys.stdin.readline().rstrip().split(' ')]
        x[l][r] += 1
    
    for i in range(1, n+1):
        for j in range(1, n+1):
            c[i][j] = c[i][j-1] + x[i][j]

    for j in range(1, n+1):
        for i in range(1, n+1):
            z[i][j] = z[i-1][j] + c[i][j]
    
    for i in range(q):
        qp, qq = [int(x) for x in sys.stdin.readline().rstrip().split(' ')]
        print(z[qq][qq] - z[qq][qp-1] - z[qp-1][qq] + z[qp-1][qp-1])


if __name__=='__main__':
    main()

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


class CumSum2d(object):
    def __init__(self, H, W):
        self.H, self.W = H, W
        self.tiles = [[0] * W for _ in range(H)]

    def add(self, x, y, c=1):
        self.tiles[y][x] += c

    def build(self):
        for y in range(self.H):
            for x in range(1, self.W):
                self.tiles[y][x] += self.tiles[y][x - 1]
        for y in range(1, self.H):
            for x in range(self.W):
                self.tiles[y][x] += self.tiles[y - 1][x]

    def get(self, sx, sy, tx, ty):
        assert sx <= tx and sy <= ty
        cnt = self.tiles[ty][tx]
        if sx > 0:
            cnt -= self.tiles[ty][sx - 1]
        if sy > 0:
            cnt -= self.tiles[sy - 1][tx]
        if sx > 0 and sy > 0:
            cnt += self.tiles[sy - 1][sx - 1]
        return cnt


cs = CumSum2d(N, N)
for i in range(M):
    l, r = map(int, input().split())
    cs.add(l - 1, r - 1)
cs.build()

for _ in range(Q):
    p, q = map(int, input().split())
    ans = cs.get(p - 1, p - 1, q - 1, q - 1)
    print(ans)

Solution (Python):
n, m, q = [int(i) for i in input().split()]
L = [[int(i) for i in input().split()] for j in range(m)]
Q = [[int(i) for i in input().split()] for j in range(q)]

A = [[0] * (n+1) for i in range (n+1)]

for l, r in L:
    A[l][r] += 1

for l in range(n, 0, -1):
    for r in range(1, n+1):
        A[l][r] += A[l][r-1]

for l in range(n-1, 0, -1):
    for r in range(1, n+1):
        A[l][r] += A[l+1][r]

for p, q in Q:
    print(A[p][q])

Solution (Python):
from copy import deepcopy

N, M, Q = [int(elem) for elem in input().split(' ')]
lines = [[int(elem) for elem in input().split(' ')] for _ in range(M)]
queries = [[int(elem) for elem in input().split(' ')] for _ in range(Q)]


def cuml_1d(N, lines, queries):
    coords = [[0] * N for _ in range(N)]
    for l, r in lines:
        coords[l - 1][r - 1] += 1

    cuml_coords = deepcopy(coords)
    for l in range(N):
        for r in range(1, N):
            cuml_coords[l][r] = cuml_coords[l][r - 1] + coords[l][r]

    for query in queries:
        p, q = query[0] - 1, query[1] - 1
        num_lines = 0
        for l in range(p, max(q + 1, N)):
            if p == 0:
                num_lines += cuml_coords[l][q]
            else:
                num_lines += cuml_coords[l][q] - cuml_coords[l][p - 1]
        print(num_lines)

cuml_1d(N, lines, queries)

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

C = [[0 for i in range(N+1)] for j in range(N+1)]
for i in range(M):
	L,R = map(int,input().split())
	C[L][R] += 1


D = [[0 for i in range(N+4)] for j in range(N+4)]
for i in range(N+1):
	for j in range(N+1):
		D[i][j+1] = D[i][j] + C[i][j]

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

Solution (Python):
from collections import Counter


def bin(ll, target, key):  
    if len(ll) < 100:
        if target in [key(a) for a in ll]:
            return [key(a) for a in ll].index(target)
        return -1

    length = len(ll)
    l, r = ll[:length // 2], ll[length // 2:]
    if key(r[0]) == target:
        if key(l[-1]) != target:
            return len(l)
        return bin(l, target, key)
    elif key(r[0]) > target:
        return bin(l, target, key)
    else:
        return len(l) + bin(r, target, key)


def main():
    n, m, q = [int(a) for a in input().split()]
    QQQ = q
    LRi = sorted([[int(a) for a in input().split()] for _ in range(m)], key=lambda it: it[0])

    PQi = [([int(a) for a in input().split()], k) for k in range(q)]
    
    

    table1 = [  
        [0] * n
        for _ in range(n)
    ]

    for l, r in LRi:
        table1[l - 1][r - 1] += 1

    table2 = [  
        [0] * n
        for _ in range(n)
    ]
    for i in range(n):
        c = 0
        for j in range(i, n):
            c += table1[i][j]
            table2[i][j] = c

    table3 = [  
        [0] * n
        for _ in range(n)
    ]
    for j in range(n):
        c = 0
        for i in reversed(range(0, j + 1)):
            c += table2[i][j]
            table3[i][j] = c

    for (p, q), k in PQi:
        print(table3[p - 1][q - 1])
    return


    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    

    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    


if __name__ == '__main__':
    main()

Solution (Python):
import bisect

N, M, Q = map(int, input().split())
trains = [list(map(int, input().split())) for i in range(M)]
queries = [list(map(int, input().split())) for i in range(Q)]

A  =[[0] * N for _ in range(N)] 
for train in trains:
    li, ri = train
    A[li - 1][ri - 1] += 1
dp = [[0] * N for _ in range(N)]
reached = [[False] * N for _ in range(N)]
def ans(left, right):
    if reached[left][right]:
        return dp[left][right]
    elif left > right:
        return 0
    elif left == right:
        dp[left][right] = A[left][right]
        reached[left][right] = True
        return A[left][right]
    else:
        dp[left][right] = ans(left, right-1) + ans(left + 1, right) + A[left][right] - ans(left + 1, right - 1)
        reached[left][right] = True
        return dp[left][right]

for q in range(Q):
    pi, qi = queries[q]
    print(ans(pi - 1, qi - 1))

Solution (Python):
N,M,Q = map(int, input().split())
train = [[0 for j1 in range(N)] for i1 in range(N)]
st = [[0 for j2 in range(N+1)] for i2 in range(N)]
s = [[0 for j3 in range(N+1)] for i3 in range(N)]

for i in range(M):
    l, r = map(int, input().split())
    train[l-1][r-1] += 1
for i in range(N):
    for j in range(N):
        st[i][j+1] = st[i][j] + train[i][j]
        
for i in range(N+1):
    s[N-1][i] = st[N-1][i]
for i in range(N-2, -1, -1):
    for j in range(N+1):
        s[i][j] = s[i+1][j] + st[i][j]
 
 
for i in range(Q):
    p, q = map(int, input().split())
    print(s[p-1][q])

Solution (Python):
from bisect import bisect_left
 
n, m, q = map(int, input().split())
LR = [0]*m
for i in range(m):
    LR[i] = list(map(int, input().split()))
P = [0]*q
Q = [0]*q
for i in range(q):
    P[i], Q[i] = map(int, input().split())
 
LR.sort(key=lambda x: (x[0], x[1]))
L = list(map(lambda x: x[0], LR))

 
C = [[0]*(n+1) for _ in range(n+1)]
for i in range(1,n+1):
    l = bisect_left(L, i)
    r = bisect_left(L, i+1)-1
    R2 = list(map(lambda x: x[1], LR[l:r+1]))
    
    for j in range(i,n+1):
        C[i][j] = bisect_left(R2, j+1)
    
 
for i in range(q):
    ans = 0
    for j in range(P[i], Q[i]+1):
        ans += C[j][Q[i]]
    print(ans)

Solution (Python):
N, M, Q = map(int, input().split())
trains = [list(map(int, input().split())) for i in range(M)]
queries = [list(map(int, input().split())) for i in range(Q)]

A  =[[0] * N for _ in range(N)] 
for train in trains:
    li, ri = train
    A[li - 1][ri - 1] += 1

dp = [[0] * N for __ in range(N)]
for i in range(N - 1, -1, -1):
    for j in range(i, N):
        if i == j:
            dp[i][j] = A[i][j]
        else:
            dp[i][j] = dp[i][j - 1] + dp[i + 1][j] + A[i][j] - dp[i + 1][j - 1]
for q in range(Q):
    pi, qi = queries[q]
    print(dp[pi - 1][ qi - 1])

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

C = [[0 for i in range(N+1)] for j in range(N+1)]
for i in range(M):
	L,R = map(int,input().split())
	C[L][R] += 1


D = [[0 for i in range(N+4)] for j in range(N+4)]
E = [0 for i in range(N+4)]
F = [[0 for i in range(N+4)] for j in range(N+4)]
for i in range(N+1):
	for j in range(N+1):
		D[i][j+1] = D[i][j] + C[i][j]
for i in range(N+1):
	E[i+1] = E[i] + D[i][i]
for i in range(N+2):
	for j in range(N+2):
		F[i+1][j] = F[i][j] + D[i][j]





for j in range(Q):
	p,q = map(int,input().split())
	s = F[q+1][q+1] - F[p][q+1] - (E[q+1] - E[p])
	print(s)

Solution (Python):
N,M,Q=map(int,input().split())
L=[0 for i in range(M)]
R=[0 for i in range(M)]
p=[0 for i in range(Q)]
q=[0 for i in range(Q)]
ans=[0 for i in range(Q)]
B=[[0 for i in range(N+1)] for i in range(N+1)]
C=[[0 for i in range(N+1)] for i in range(N+1)]
D=[[0 for i in range(N+1)] for i in range(N+1)]
for i in range(M):
    L[i],R[i]=map(int,input().split())
    L[i]-=1
    R[i]-=1
for i in range(Q):
    p[i],q[i]=map(int,input().split())
    p[i]-=1
    q[i]-=1
for i in range(M):
    B[R[i]][0]+=1
    B[R[i]][L[i]+1]-=1
    B[N][0]-=1
    B[N][L[i]+1]+=1
for i in range(N+1):
    for j in range(N+1):
        if i==0:
            C[i][j]=B[i][j]
        else:
            C[i][j]=B[i][j]+C[i-1][j]
for i in range(N+1):
    for j in range(N+1):
        if j==0:
            D[i][j]=C[i][j]
        else:
            D[i][j]=C[i][j]+D[i][j-1]
for i in range(Q):
    ans[i]=D[q[i]][p[i]]

for line in ans:
    print(line)

Solution (Python):
import numpy as np

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

mat = np.zeros((n, n), dtype=int)

for i in range(m):
    l, r = map(int, input().split())
    mat[l-1, r-1] += 1
mat = np.flipud(mat)
matmul = np.cumsum(mat, axis=0)
matmul = np.flipud(matmul)
matmul2 = np.cumsum(matmul, axis=1)

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

Solution (Python):
N,M,Q = map(int,input().split())
LR = [list(map(int,input().split())) for _ in range(M)]
pq = [list(map(int,input().split())) for _ in range(Q)]


L = [[0] * N for _ in range(N)]
for l,r in LR:
    L[l-1][r-1] += 1
for i in range(1,N):
    for j in range(N - i):
        L[j][j+i] += L[j][j+i-1] + L[j+1][i+j] - L[j+1][j+i-1]
for p,q in pq:
    print(L[p-1][q-1])

Solution (Python):
N,M,Q = map(int,input().split())
src = [tuple(map(lambda x:int(x)-1,input().split())) for i in range(M)]
src.sort(reverse=True)
qs = [tuple(map(lambda x:int(x)-1,input().split())) for i in range(Q)]

q_arr = [[] for i in range(N)]
for i,(l,r) in enumerate(qs):
    q_arr[l].append((r,i))

bit = [0] * (N+2)
def bit_add(a,w):
    x = a
    while x <= N:
        bit[x] += w
        x += (x & -x)

def bit_sum(a):
    x = a
    ret = 0
    while x > 0:
        ret += bit[x]
        x -= (x & -x)
    return ret

ans = [None] * Q

last_l = N-1
for l,r in src:
    while last_l > l:
        for qr,qi in q_arr[last_l]:
            ans[qi] = bit_sum(qr+1)
        last_l -= 1
    bit_add(r+1, 1)
while last_l >= 0:
    for qr,qi in q_arr[last_l]:
        ans[qi] = bit_sum(qr+1)
    last_l -= 1

print(*ans, sep='\n')

Solution (Python):
from itertools import accumulate

N,M,Q=map(int,input().split())
ST=[[0 for x in range(N+2)]for y in range(N+2)]

for i in range(M):
  s,t=map(int,input().split())
  ST[1][t]+=1
  ST[s+1][t]-=1
  ST[1][N+1]+=1
  ST[s+1][N+1]-=1

ST1 = [list(accumulate(l)) for l in zip(*ST)]
ST2 = [list(accumulate(l)) for l in zip(*ST1)]

for i in range(Q):
  s,t=map(int,input().split())
  print(ST2[s][t])

Solution (Python):
n,m,q=map(int,input().split())
d=[[0 for j in range(n)] for i in range(n)]
for i in range(m):
	l,r=map(int,input().split())
	d[n-l][r-1]+=1
for l in range(n):
	for r in range(1,n):
		d[l][r]+=d[l][r-1]
for l in range(1,n):
	for r in range(n):
		d[l][r]+=d[l-1][r]
for i in range(q):
	l,r=map(int,input().split())
	print(d[n-l][r-1])

Solution (Python):
N, M, Q = map(int, input().split())
LR = [list(map(int, input().split())) for _ in range(M)]
pq = [list(map(int, input().split())) for _ in range(Q)]

table = [[0 for _i in range(N+1)] for _j in range(N+1)]
accum = [[0 for _i in range(N+1)] for _j in range(N+1)]
accum2 = [[0 for _i in range(N+1)] for _j in range(N+1)]

for line in LR:
    table[line[0]][line[1]] += 1

for i in range(1, N+1):
    for j in range(1, N+1):
        accum[i][j] = accum[i][j-1] + table[i][j]

for i in range(1, N+1):
    for j in range(1, N+1):
        accum2[i][j] = accum2[i-1][j] + accum[i][j]





for question in pq:
    p = question[0]
    q = question[1]
    print(accum2[q][q] - accum2[p-1][q] - accum2[q][p-1] + accum2[p-1][p-1])

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

for i in range(n):
    for j in range(1, n):
        T[i][j] += T[i][j - 1]

for j in range(n):
    for i in range(n - 2, -1, -1):
        T[i][j] += T[i + 1][j]

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

Solution (Python):
n, m, qqq = map(int, input().split())
DP = [[0 for _ in range(n)]for __ in range(n)]

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



for i in range(n-1)[::-1]:
    for j in range(1,n):
        DP[i][j] += DP[i+1][j]+DP[i][j-1]-DP[i+1][j-1]

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

Solution (Python):
N, M, Q=list(map(int,input().split()))
LR=[list(map(int,input().split()))+[0] for _ in range(M)]
pq=[list(map(int,input().split()))+[1]+[_] for _ in range(Q)]




a=LR+pq

a.sort(key=lambda x:x[1])

b=[0]*(N+1)
ans=[]
for i in a:
    if i[2]==0:
        b[i[0]]+=1
    else:
        ans.append([sum(b[i[0]:i[1]+1]), i[3]])
    

ans.sort(key=lambda x:x[1])

for i in ans:
    print(i[0])

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

LR=[None]*M
for i in range(M):
    LR[i]=list(map(int,input().split()))

pq=[None]*Q
for i in range(Q):
    pq[i]=list(map(int,input().split()))


LIST=[None]*(N+1)
for i in range(N+1):
    LIST[i]=[0 for j in range(N+1)]


for i in range(M):
    LIST[LR[i][0]][LR[i][1]]+=1

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

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

for i in range(Q):
    print(LIST[pq[i][0]][pq[i][1]])

Solution (Python):


from collections import deque
import itertools as it
import sys
import math

sys.setrecursionlimit(10000000)

N, M, Q = map(int, raw_input().split())

cnt = [[0] * 550 for i in range(550)]

for loop in range(M):
    L, R = map(int, raw_input().split())
    L -= 1
    R -= 1
    cnt[L][R] += 1

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

for i in range(510):
    for j in range(500, 0, -1):
        cnt[j - 1][i] += cnt[j][i]

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

Solution (Python):
import numpy as np
n,m,q = map(int,raw_input().split())

imos = [[0 for i in xrange(n)] for j in xrange(n)]

for i in xrange(m):
	f,t = map(int,raw_input().split())
	f -= 1
	t -= 1
	imos[f][t] += 1

for i in range(n-1,0,-1):
	for j in range(n):
		imos[i-1][j] = imos[i][j] + imos[i-1][j]

for i in xrange(n):
	imos[i] = np.cumsum(imos[i])

for i in xrange(q):
	a,b = map(int,raw_input().split())
	print imos[a-1][b-1]

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

A=[]	
B=[]	

for i in range(N+1):
	a=[0]*(N+1)
	B.append(a)

for i in range(M):
	l, r = map(int, input().split())		
	A.append( (l,r) )
	B[l][r]+=1




for iR in range(1,N+1):
	for iC in range(1,N+1):
		B[iR][iC] += B[iR][iC-1]

for iC in range(1,N+1):
	for iR in range(iC, 1, -1):
		B[iR-1][iC] += B[iR][iC]





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

Solution (Python):
N, M, Q = map(int, input().split());
L = [];
R = [];

for i in range(M):
    Lnew, Rnew = map(int, input().split());
    L.append(Lnew);
    R.append(Rnew);

p = [];
q = [];

for i in range(Q):
    pnew, qnew = map(int, input().split());
    p.append(pnew);
    q.append(qnew);


trainList = [0] * (N**2);
ansList   = [0] * (N**2);

for i in range(M):
    trainList[(R[i]-L[i])*N+(L[i]-1)]+=1;

for i in range(N**2):
    if(i<N):
        ansList[i]=trainList[i];
    elif(i<N*2):
        ansList[i]=trainList[i]+ansList[i-N]+ansList[i-N+1];
    else:
        ansList[i]=trainList[i]+ansList[i-N]+ansList[i-N+1]-ansList[i-2*N+1];

for i in range(Q):
    ln=q[i]-p[i];
    print(ansList[ln*N+p[i]-1]);

Solution (Python):
def main():
    n, m, q = [int(i) for i in raw_input().strip().split()]
    f = [[0 for j in xrange(n)] for i in xrange(n)]
    for i in xrange(m):
        l, r = [int(i) - 1 for i in raw_input().strip().split()]
        f[l][r] += 1
    for d in xrange(1, n):
        for i in xrange(0, n - d):
            f[i][i + d] += f[i][i + d - 1] + f[i + 1][i + d] - f[i + 1][i + d - 1]
    for i in xrange(q):
        p, q = [int(i) - 1 for i in raw_input().strip().split()]
        print f[p][q]

if __name__ == '__main__':
    main()

Solution (Python):
n,m,q=map(int,input().split())
d=[[0 for j in range(n)] for i in range(n)]
for i in range(m):
	l,r=map(lambda x:int(x)-1,input().split())
	d[l][r]+=1
for l in range(n):
	for r in range(1,n):
		d[l][r]+=d[l][r-1]
for l in range(n-1,0,-1):
	for r in range(n):
		d[l-1][r]+=d[l][r]
for i in range(q):
	l,r=map(lambda x:int(x)-1,input().split())
	print(d[l][r])

Solution (Python):
from itertools import accumulate

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

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

Ass = [list(accumulate(Ts)) for Ts in Tss]

Bss = [[0] * N for i in range(N)]
for j in range(N):
    Bss[N - 1][j] = Ass[N - 1][j]
    for i in reversed(range(N - 1)):
        Bss[i][j] = Bss[i + 1][j] + Ass[i][j]

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

Solution (Python):


n, m, qq = map(int, input().split())

lr = [[0 for i in range(n + 1)] for j in range(n + 1)]
acc = [[0 for i in range(n + 1)] for j in range(n + 1)]

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

for i in range(1, n + 1):
    for j in range(1, n + 1):
        acc[i][j] = acc[i][j-1] + lr[i][j]

res = []
for _ in range(qq):
    ans = 0
    p, q = map(int, input().split())
    for i in range(p, q + 1):
        ans += acc[i][q] - acc[i][i - 1]
    res.append(ans)

for row in res:
    print(row)

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

    city[1][r] += 1
    city[l+1][r] -= 1
    if l==r:
        same[l] += 1

"""
print()
for c in city[1:n+1]:
    print(c[1:n+1])
"""

for j in range(n+2):
    for i in range(1, n+2):
        city[j][i] += city[j][i-1]

for i in range(n+2):
    for j in range(1, n+2):
        city[j][i] += city[j-1][i]

"""
print()
for c in city[1:n+1]:
    print(c[1:n+1])
"""

for _ in range(q):
    x, y = map(int, input().split())
    if x==y:
        print(same[x])
    else:
        print(city[x][y])

Solution (Python):
n,m,q = (int(i) for i in input().split())
x = [[0 for i in range(n)] for i in range(n+1)]
for _ in range(m):
	l,r = (int(i) for i in input().split())
	x[0][r-1]+=1
	x[l][r-1]-=1
for i in range(n+1):
	for j in range(1,n): x[i][j]+=x[i][j-1]
for i in range(n):
	for j in range(1,n+1): x[j][i]+=x[j-1][i]
for _ in range(q):
	p,q = (int(i) for i in input().split())
	print(x[p-1][q-1])

Solution (Python):
n,m,q=map(int, input().split())
lr=[list(map(int,input().split())) for _ in range(m)]
pq=[list(map(int,input().split())) for _ in range(q)]
x=[[0 for _ in range(n)] for _ in range(n)]
for t in lr:
    x[t[0]-1][t[1]-1]+=1
for i in range(n):
    k=False
    for j in range(n):
        if k:
            x[i][j]+=x[i][j-1]
        elif x[i][j]>0:
            k=True
            
for i in range(n-1,0,-1):
    for j in range(n-1,-1,-1):
        x[i-1][j]+=x[i][j]
for t in pq:
    print(x[t[0]-1][t[1]-1])

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

LR = [list(map(int, input().split())) for i in range(M)]
pq = [list(map(int, input().split())) for i in range(Q)]

res = [[0]*N for i in range(N)]

def lsadd(L,R):
    L-=1
    R-=1
    for i in range(0,L+1):  
        res[i][R] += 1

for l,r in LR:
    lsadd(l,r)

for p,q in pq:
    print(sum(res[p-1][:q]))

Solution (Python):
from sys import exit, setrecursionlimit, stderr
from functools import reduce
from itertools import *
from collections import defaultdict
from bisect import bisect

def read():
  return int(input())

def reads():
  return [int(x) for x in input().split()]

N, M, Q = reads()

mat = [[0] * N for _ in range(N)]
for _ in range(M):
  l, r = reads()
  l, r = l-1, r-1
  mat[l][r] += 1

acc = [[0] * (N+1) for _ in range(N+1)]
for i, j in product(range(N), range(N)):
  acc[i+1][j+1] = acc[i][j+1] + acc[i+1][j] - acc[i][j] + mat[i][j]

for _ in range(Q):
  p, q = reads()
  p, q = p-1, q-1
  ans = acc[N][q+1] - acc[p][q+1]
  print(ans)