Problem: 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.

Submission attempts (in order):
n, m, q = map(int, input().split())
lr_array = [[int(x) for x in input().split()] for y in range(m)]
pq_array = [[int(x) for x in input().split()] for y in range(q)]


def solve1():
    table = [[0 for x in range(n + 1)] for y in range(n + 1)]
    for l, r in lr_array:
        table[l][r] += 1
    # for row in table:
    #     print(row)
    # print("---------")
    for i in range(1, n + 1):
        for j in range(1, n + 1):
            table[i][j] = table[i][j - 1] + table[i][j]
    # for row in table:
    #     print(row)
    for p, q in pq_array:
        res = 0
        for i in range(p, q + 1):
            # print(i)
            res += table[i][q]
        print(res)

    return 0





def solve2():
    table = [[0 for x in range(n + 1)] for y in range(n + 1)]
    for l, r in lr_array:
        table[l][r] += 1
    # for row in table:
    #     print(row)
    # print("---------")

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

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

    
    
    for p, q in pq_array:
        print(table[q][q] + table[p][p] - table[q][p-1] - table[p-1][q])


if __name__ == '__main__':
    # solve1()
    solve2()


n, m, q = map(int, input().split())
lr_array = [[int(x) for x in input().split()] for y in range(m)]
pq_array = [[int(x) for x in input().split()] for y in range(q)]


def solve1():
    table = [[0 for x in range(n + 1)] for y in range(n + 1)]
    for l, r in lr_array:
        table[l][r] += 1
    # for row in table:
    #     print(row)
    # print("---------")
    for i in range(1, n + 1):
        for j in range(1, n + 1):
            table[i][j] = table[i][j - 1] + table[i][j]
    # for row in table:
    #     print(row)
    for p, q in pq_array:
        res = 0
        for i in range(p, q + 1):
            # print(i)
            res += table[i][q]
        print(res)

    return 0





def solve2():
    table = [[0 for x in range(n + 1)] for y in range(n + 1)]
    for l, r in lr_array:
        table[l][r] += 1
    # for row in table:
    #     print(row)
    # print("---------")

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

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

    # for row in table:
    #     print(row)

    
    
    for p, q in pq_array:
        print(table[q][q] + table[p-1][p-1] - table[q][p-1] - table[p-1][q])


if __name__ == '__main__':
    # solve1()
    solve2()


Verdicts: Wrong Answer

Accepted