Buggy python submission (verdict: Time Limit Exceeded):
import bisect
import sys
sys.setrecursionlimit(10**9)

def mi(): return map(int,input().split())
def ii(): return int(input())
def isp(): return input().split()
def deb(text): print("-------\n{}\n-------".format(text))

INF=10**20
def main():
    N,M,Q=mi()
    Ls = []
    Rs = []
    for i in range(M):
        L,R=mi()
        Ls.append((L,i))
        Rs.append((R,i))

    Ls.sort()
    Rs.sort()

    L_indexs = [set()] * (M+1)
    R_indexs = [set()] * (M+1)

    _Ls = []
    _Rs = []
    for i in range(M):
        L,L_i = Ls[M-1-i]
        R,R_i = Rs[i]

        L_indexs[i+1] = L_indexs[i] | set([L_i])
        R_indexs[i+1] = R_indexs[i] | set([R_i])

        _Ls.append(Ls[i][0])
        _Rs.append(R)

        
        
    # print(L_indexs)
    # print(L_indexs,R_indexs)
    for i in range(Q):
        p,q=mi()
        L_i = bisect.bisect_left(_Ls,p)

        # print(L_i)
        
        R_i = bisect.bisect_right(_Rs,q)
        if R_i == M:
            R_i -= 1
        elif Rs[R_i][0] != q:
            R_i -= 1

        ans = 0
        # print(M-L_i,R_i, L_indexs[M-L_i],R_indexs[R_i+1])
        if R_indexs[R_i+1] > L_indexs[M-L_i]:
            for j in L_indexs[M-L_i]:
                if j in R_indexs[R_i+1]:
                    ans += 1
        else:
            for j in R_indexs[R_i+1]:
                if j in L_indexs[M-L_i]:
                    ans += 1
        
        print(ans)



if __name__ == "__main__":
    main()

Fixed submission:
import sys
sys.setrecursionlimit(10**9)

def mi(): return map(int,input().split())
def ii(): return int(input())
def isp(): return input().split()
def deb(text): print("-------\n{}\n-------".format(text))

INF=10**20
def main():
    N,M,Q=mi()
    
    count = [[0] * (N+1) for _ in range(N+1)]
    for i in range(M):
        L,R=mi()
        count[L][R] += 1
    
    # print(count)
    dp = [[0] * (N+1) for _ in range(N+1)]

    for w in range(1,N+1):
        for h in range(1,N+1):
            l,r=N+1-w,h
            dp[w][h] += dp[w][h-1] + dp[w-1][h] - dp[w-1][h-1] + count[l][r]


    # print(dp)
    for i in range(Q):
        p,q=mi()
        w,h=N+1-p,q
        # print(w,h)
        print(dp[w][h])

            






if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import bisect
import sys
sys.setrecursionlimit(10**9)

def mi(): return map(int,input().split())
def ii(): return int(input())
def isp(): return input().split()
def deb(text): print("-------\n{}\n-------".format(text))

INF=10**20
def main():
    N,M,Q=mi()
    Ls = []
    Rs = []
    for i in range(M):
        L,R=mi()
        Ls.append((L,i))
        Rs.append((R,i))

    Ls.sort()
    Rs.sort()

    L_indexs = [set()] * (M+1)
    R_indexs = [set()] * (M+1)

    _Ls = []
    _Rs = []
    for i in range(M):
        L,L_i = Ls[i]
        R,R_i = Rs[i]

        L_indexs[i+1] = L_indexs[i] | set([L_i])
        R_indexs[i+1] = R_indexs[i] | set([R_i])

        _Ls.append(L)
        _Rs.append(R)

        
        

    # print(L_indexs,R_indexs)
    for i in range(Q):
        p,q=mi()
        L_i = bisect.bisect_left(_Ls,p)

        # print(L_i)
        
        R_i = bisect.bisect_right(_Rs,q)
        if R_i == M:
            R_i -= 1
        elif Rs[R_i][0] != q:
            R_i -= 1

        ans = 0
        # print(L_i,R_i,L_indexs[-1] - L_indexs[L_i],R_indexs[R_i+1])
        for j in R_indexs[R_i+1]:
            if j in L_indexs[-1] - L_indexs[L_i]:
                ans += 1
        
        print(ans)



        




if __name__ == "__main__":
    main()

Fixed submission:
import sys
sys.setrecursionlimit(10**9)

def mi(): return map(int,input().split())
def ii(): return int(input())
def isp(): return input().split()
def deb(text): print("-------\n{}\n-------".format(text))

INF=10**20
def main():
    N,M,Q=mi()
    
    count = [[0] * (N+1) for _ in range(N+1)]
    for i in range(M):
        L,R=mi()
        count[L][R] += 1
    
    # print(count)
    dp = [[0] * (N+1) for _ in range(N+1)]

    for w in range(1,N+1):
        for h in range(1,N+1):
            l,r=N+1-w,h
            dp[w][h] += dp[w][h-1] + dp[w-1][h] - dp[w-1][h-1] + count[l][r]


    # print(dp)
    for i in range(Q):
        p,q=mi()
        w,h=N+1-p,q
        # print(w,h)
        print(dp[w][h])

            






if __name__ == "__main__":
    main()