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())
    rail = []
    for i in range(M):
        r = list(map(int, input().split()))
        rail.append(r)
     
    query = []
    for i in range(Q):
        q = list(map(int, input().split()))
        query.append(q)
     
    f = [[0 for i in range(N)] for j in range(N)]
    g = [[0 for i in range(N)] for j in range(N)]
     
    for i in range(M):
        f[rail[i][0]-1][rail[i][1]-1] += 1
     
    for i in range(N):
        j = 0
        while j + i < N:
            if i == 0:
                g[j][j+i] = f[j][j+i]
            else:
                g[j][j+i] = f[j][j+i] + g[j+1][j+i] + g[j][j+i-1] - g[j+1][j+i-1]
            j += 1
     
    for i in range(Q):
        print(g[query[i][0]-1][query[i][1]-1])

#encoding utf-8

import numpy as np

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)

p = []
q = []

for i in range(Q):
    pa, qa = map(int, input().split())
    p.append(pa)
    q.append(qa)

MAP = np.zeros((N, N))
for i in range(M):
    MAP[L[i]-1][R[i]-1] += 1

C = np.zeros((N, N))
C[0][0] = MAP[0][0]
for i in range(N):
    count = 0
    for j in range(N):
        count += MAP[i][j]
        C[i][j] = count

print(MAP)
print(C)

for i in range(Q):
    count = 0
    for j in range(q[i]-p[i]+1):
        if j == 0:
            count += C[p[i]-1+j][q[i]-1]
        else:
            count += C[p[i]-1+j][q[i]-1]-C[p[i]-1+j][p[i]-1]
    print(int(count))


#encoding utf-8

import numpy as np

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)

p = []
q = []

for i in range(Q):
    pa, qa = map(int, input().split())
    p.append(pa)
    q.append(qa)

MAP = np.zeros((N, N))
for i in range(M):
    MAP[L[i]-1][R[i]-1] += 1

C = np.zeros((N, N))
C[0][0] = MAP[0][0]
for i in range(N):
    count = 0
    for j in range(N):
        count += MAP[i][j]
        C[i][j] = count


for i in range(Q):
    count = 0
    for j in range(q[i]-p[i]+1):
        count += C[p[i]-1+j][q[i]-1]-C[p[i]-1+j][p[i]-1]
    print(int(count))



N, M, Q = map(int, input().split())
rail = []
for i in range(M):
    r = list(map(int, input().split()))
    rail.append(r)
 
query = []
for i in range(Q):
    q = list(map(int, input().split()))
    query.append(q)
 
f = [[0 for i in range(N)] for j in range(N)]
g = [[0 for i in range(N)] for j in range(N)]
 
for i in range(M):
    f[rail[i][0]-1][rail[i][1]-1] += 1
 
for i in range(N):
    j = 0
    while j + i < N:
        if i == 0:
            g[j][j+i] = f[j][j+i]
        else:
            g[j][j+i] = f[j][j+i] + g[j+1][j+i] + g[j][j+i-1] - g[j+1][j+i-1]
        j += 1
 
for i in range(Q):
    print(g[query[i][0]-1][query[i][1]-1])


Verdicts: Runtime Error

Wrong Answer

Wrong Answer

Accepted