TnT/Multi_CodeNet4Repair huggingface dataset:
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):
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

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

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

for _ in range(M):
    a, b = map(int, input().split())
    mat[a][b] = 1


def solve():

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

    ans = []

    for _ in range(Q):
        ql, qr = map(int, input().split())
        tmp = 0
        for i in range(ql, qr+1):
            tmp += mat[i][qr] - mat[i][ql-1]
        ans.append(tmp)

    for a in ans:
        print(a)


def solve2():

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

    ans = [0]*Q
    for i in range(Q):
        ql, qr = map(int, input().split())
        t = mat[qr][qr] - mat[ql-1][qr] - mat[qr][ql-1] + mat[ql-1][ql-1]
        ans[i] = t

    for a in ans:
        print(a+1)


solve2()


# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

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

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

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

kukan.sort()

li = [0]*(N+1)
ans = [0]*Q

for t, flag, s in kukan:
    if flag == -1:
        li[s] += 1
    else:
        ans[flag] = sum(li[s:t+1])

for a in ans:
    print(a)


Verdicts: Wrong Answer

Accepted
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(" "))

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

print(ns)

for i in range(q):
    count = 0
    (ql, qr) = map(int, input().split(" "))
    for j in range(ql, qr + 1):
        for k in range(j, qr + 1):
            count += ns[j][k]
    print(count)


(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])

Verdicts: Wrong Answer

Accepted
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())

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

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

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

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

    ans = x[p][q]
    print(ans)

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

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

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

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

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

    ans = x[N][q] - x[p - 1][q]
    print(ans)

Verdicts: Wrong Answer

Accepted
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())

import numpy as np
matrix = np.array([[0 for _ in range(N+1)] for _ in range(N+1)], dtype=np.int16)

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

for i in range(1, N+1):
    for j in range(i, N+1):
        w = pairs[i][j]
        if w > 0:
            matrix[:i+1,j:] += w

pairs = [[matrix[i,j] for j in range(N+1)] for i in range(N+1)]


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

import numpy as np
matrix = np.array([[0 for _ in range(N+1)] for _ in range(N+1)], dtype=np.int16)

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


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

class Cell:
    def __init__(self):
        self.value = 0
        self.L = 0
    def __repr__(self):
        return str((self.value, self.L))

pairs = [[Cell() for _ in range(N+1)] for _ in range(N+1)]
for L, R in (map(int, input().split()) for _ in range(M)):
    cell = pairs[L][R]
    cell.value += 1
    cell.L = cell.value

for i in range(N-1, 0, -1):
    for j in range(i+1, N+1):
        cell = pairs[i][j]
        cell.L += pairs[i][j-1].L
        cell.value = cell.L + pairs[i+1][j].value
for p, q in (map(int, input().split()) for _ in range(Q)):
    print(pairs[p][q].value)


Verdicts: Wrong Answer

Wrong Answer

Accepted
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):
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

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

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

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


import numpy as np
N, M , Q = map(int, input().split())

LR = np.array([np.zeros(N+2-i, dtype=np.int) for i in range(N+2)])
for i in range(M):
  L, R = map(int, input().split())
  LR[L][R-L+1] += 1

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


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

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

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


import sys
from itertools import accumulate
N, M, Q = map(int, sys.stdin.readline().split())
 
LR = [[0 for _ in range(N-i)] for i in range(N)]
for i in range(M):
  L, R = map(int, sys.stdin.readline().split())
  LR[L-1][R-L] += 1
 
for i in range(N-2,-1,-1):
  acc = accumulate(LR[i])
  next(acc)
  for j in range(1, N-i):
    LR[i][j] = next(acc) + LR[i+1][j-1]
 
for i in range(Q):
  p, q = map(int, sys.stdin.readline().split())
  sys.stdout.write(str(LR[p-1][q-p])+"\n")


Verdicts: Runtime Error

Runtime Error

Time Limit Exceeded

Runtime Error

Accepted
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):
import numpy as np

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

    check = np.zeros((N+1, N+1))

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

    # print(check)
    for i in range(1, N+1):
        check[i] += check[i-1]
    for i in range(1, N+1):
        check[:,i] += check[:,i-1]
    # print(check)

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

if __name__ == "__main__":
    main()


import sys
import numpy as np
input = sys.stdin.readline

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

    check = np.zeros((N+1, N+1))

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

    # print(check)
    for i in range(1, N+1):
        check[i] += check[i-1]
    for i in range(1, N+1):
        check[:,i] += check[:,i-1]
    # print(check)

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

if __name__ == "__main__":
    main()


Verdicts: Wrong Answer

Accepted
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):
# import sys
# input = sys.stdin.readlines()
n, m, q = map(int, input().split())

d = [[0 for j in range(n + 1)] for i in range(n + 1)]
a = [[0 for j in range(n + 1)] for i in range(n + 1)]

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

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


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


# import sys
# input = sys.stdin.readlines()
n, m, q = map(int, input().split())

d = [[0 for j in range(n + 1)] for i in range(n + 1)]
a = [[0 for j in range(n + 1)] for i in range(n + 1)]

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

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

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


Verdicts: Wrong Answer

Accepted
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())
table = [[0 for _ in range(N+1)] for _ in range(N+1)]
for _ in range(M):
    l, r = map(int, input().split())
    table[l][r] += 1
cum_sum2 = [[0 for _ in range(N+1)] for _ in range(N+1)]
for i, j in product(range(1, N+1), repeat=2):
    cum_sum2[i][j] += table[i][j] + cum_sum2[i-1][j] + cum_sum2[i][j-1] - cum_sum2[i-1][j-1]
for _ in range(Q):
    p, q = map(int, input().split())
    ans = cum_sum2[q][q] - cum_sum2[p-1][q] - cum_sum2[q][p-1] + cum_sum2[p-1][p-1]
    print(ans)

from itertools import product

N, M, Q = map(int, input().split())
table = [[0 for _ in range(N+1)] for _ in range(N+1)]
for _ in range(M):
    l, r = map(int, input().split())
    table[l][r] += 1
cum_sum2 = [[0 for _ in range(N+1)] for _ in range(N+1)]
for i, j in product(range(1, N+1), repeat=2):
    cum_sum2[i][j] += table[i][j] + cum_sum2[i-1][j] + cum_sum2[i][j-1] - cum_sum2[i-1][j-1]
for _ in range(Q):
    p, q = map(int, input().split())
    ans = cum_sum2[q][q] - cum_sum2[p-1][q] - cum_sum2[q][p-1] + cum_sum2[p-1][p-1]
    print(ans)

Verdicts: Runtime Error

Accepted
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())

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

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


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]

# C[l][l] + ... + C[l][r] = D[l][r+1] - D[l][l]
# C[i][i] + ... + C[i][r] = D[i][r+1] - D[i][i]
# C[r][r] + ... + C[r][r] = D[r][r+1] - D[r][r]

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)



Verdicts: Runtime Error

Accepted
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 = [int(_) for _ in input().split()]
train = [[int(_) for _ in input().split()] for i in range(M)]
question = [[int(_) for _ in input().split()] for i in range(Q)]

nl = [[0 for i in range(N)] for j in range(N)]
for t in train:
    i = t[0] - 1
    j = t[1] - 1
    nl[i][j] += 1

l = [[0 for i in range(N)] for j in range(N)]
for i in range(N):
    s = 0
    for j in range(N):
        l[i][j] = s + nl[i][j]
        s = l[i][j]

print(nl, l)

for k in range(Q):
    p = question[k][0]
    q = question[k][1]
    ans = 0
    for i in range(p-1, q):
        if p == 1:
            d = l[i][q-1]
        else:
            d = l[i][q-1] - l[i][p-2]
        ans += d
    print(ans)



N, M, Q = [int(_) for _ in input().split()]

l = [[0 for i in range(N+1)] for j in range(N+2)]
for t in [input().split() for _ in range(M)]:
    i = int(t[0])
    j = int(t[1])
    l[i][j] += 1

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

for k in [input().split() for _ in range(Q)]:
    p = int(k[0])
    q = int(k[1])
    print(l[p][q])


Verdicts: Wrong Answer

Accepted
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):
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(mat, axis=1)[::-1], axis=0)[::-1]

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


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])


Verdicts: Runtime Error

Accepted
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())
num = [[0 for i in range(N)] for j in range(N)]
lr = [list(map(int,input().split())) for i in range(M)]
for l,r in lr:
    num[l-1][r-1] += 1

for j in range(N):
    for i in range(N-1,0,-1):
        num[i-1][j] += num[i][j]
for i in range(N):
    for j in range(N-1):
        num[i][j+1] += num[i][j]
pq = [list(map(int,input().split())) for i in range(M)]
for p,q in pq:
    print(num[p-1][q-1])


import sys
def input(): return sys.stdin.readline().strip()
N,M,Q = map(int,input().split())
num = [[0 for i in range(N)] for j in range(N)]
lr = [list(map(int,input().split())) for i in range(M)]
for l,r in lr:
    num[l-1][r-1] += 1

for j in range(N):
    for i in range(N-1,0,-1):
        num[i-1][j] += num[i][j]
for i in range(N):
    for j in range(N-1):
        num[i][j+1] += num[i][j]
pq = [list(map(int,input().split())) for i in range(Q)]
ans = []
for p,q in pq:
    ans.append(num[p-1][q-1])
print(*ans,sep='\n')

Verdicts: Runtime Error

Accepted
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_2d = [[0 for i in range(n)] for i in range(n)]
for i in range(m):
    L,R = map(int,input().split(" "))
    LR_2d[L-1][R-1] += 1
LR_2dsum = [[0 for i in range(n)] for i in range(n)]
for i in range(n):
    LR_2dsum[i][0] = LR_2d[i][0]
    for j in range(1,n):
        LR_2dsum[i][j] = LR_2dsum[i][j-1] + LR_2d[i][j]
for i in range(q):
    ans = 0
    p_i,q_i = map(int,input().split(" "))
    for j in range(p_i-1,q_i):
        ans_j = LR_2dsum[j][q_i-1] - LR_2dsum[j][max(0,p_i-2)]
        ans += ans_j
    print(ans)

n,m,q = map(int,input().split(" "))
LR_2d = [[0 for i in range(n)] for i in range(n)]
for i in range(m):
    L,R = map(int,input().split(" "))
    LR_2d[L-1][R-1] += 1
LR_2dsum = [[0 for i in range(n)] for i in range(n)]
for i in range(n):
    LR_2dsum[i][0] = LR_2d[i][0]
    for j in range(1,n):
        LR_2dsum[i][j] = LR_2dsum[i][j-1] + LR_2d[i][j]
for i in LR_2dsum:
    print(i)
for i in range(q):
    ans = 0
    p_i,q_i = map(int,input().split(" "))
    for j in range(p_i-1,q_i):
        ans_j = LR_2dsum[j][q_i-1] - LR_2dsum[j][max(0,p_i-2)]
        ans += ans_j
    print(ans)

n,m,q = map(int,input().split(" "))
LR_2d = [[0 for i in range(n+1)] for i in range(n+1)]
for i in range(m):
    L,R = map(int,input().split(" "))
    LR_2d[L][R] += 1

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

for i in range(q):
    p_i,q_i = map(int,input().split(" "))
    ans = LR_2dsum[p_i-1][p_i-1] - LR_2dsum[p_i-1][q_i] - LR_2dsum[q_i][p_i-1] + LR_2dsum[q_i][q_i]
    print(ans)

Verdicts: Wrong Answer

Wrong Answer

Accepted
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):
import numpy as np
n,m,q=map(int,input().split())
s=np.zeros((n,n))
for i in range(m):
    l,r=map(int,input().split())
    s[n-l][r-1]+=1
s=np.cumsum(np.cumsum(s,axis=0),axis=1)
print(s)
for i in range(q):
    d,t=map(int,input().split())
    print(int(s[n-d][t-1]))

import numpy as np
n,m,q=map(int,input().split())
s=np.zeros((n,n))
for i in range(m):
    l,r=map(int,input().split())
    s[n-l][r-1]+=1
s=np.cumsum(np.cumsum(s,axis=0),axis=1)
for i in range(q):
    d,t=map(int,input().split())
    print(int(s[n-d][t-1]))

Verdicts: Wrong Answer

Accepted
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())
dataList = [[0 for xIndex in range(n+1)]for yIndex in range(n+1)]

for i in range(m):
    xTemp,yTemp = map(int,input().split())
    dataList[yTemp][xTemp]+=1
pqList=[list(map(lambda x:int(x),input().split()))for i in range(q)]
print(dataList)
for yIndex in range(1,n+1):
    for xIndex in range(1,n+1):
        dataList[yIndex][xIndex]+=dataList[yIndex][xIndex-1]
for yIndex in range(1,n+1):
    for xIndex in range(1,n+1):
        dataList[yIndex][xIndex]+=dataList[yIndex-1][xIndex]
print(dataList)

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

n,m,q= map(int,input().split())
lrList=[list(map(int,input().split()))for i in range(m)]
pqList=[list(map(int,input().split()))for i in range(q)]
for pq in pqList:
    ans = 0
    for lr in lrList:
        ans +=(pq[0] <= lr[0] and pq[1] >= lr[1])
    print(1)

n,m,q= map(int,input().split())
dataList = [[0 for xIndex in range(n+1)]for yIndex in range(n+1)]

for i in range(m):
    xTemp,yTemp = map(int,input().split())
    dataList[yTemp][xTemp]+=1
pqList=[list(map(lambda x:int(x),input().split()))for i in range(q)]
for yIndex in range(1,n+1):
    for xIndex in range(1,n+1):
        dataList[yIndex][xIndex]+=dataList[yIndex][xIndex-1]
for yIndex in range(1,n+1):
    for xIndex in range(1,n+1):
        dataList[yIndex][xIndex]+=dataList[yIndex-1][xIndex]

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

Verdicts: Wrong Answer

Wrong Answer

Accepted
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())
dp=[[0]*-~N for _ in[0]*-~N]
for _ in[0]*M:
    L,R=map(int,input().split())
    for i in range(1,L+1):
        for j in range(R,N+1):
            dp[i][j] += 1
            print(i,j)
for _ in[0]*Q:
    p,q=map(int,input().split())
    print(dp[p][q])

import sys
import numpy as np
def main():
    s = sys.stdin.readlines()
    N, M, _ = map(int, s[0].split())
    X = np.zeros((N, N), dtype=int)
    for L, R in (map(int, e.split()) for e in s[1:M + 1]): X[L - 1][R - 1] += 1
    S = np.cumsum(np.cumsum(X, axis=1)[::-1], axis=0)[::-1]
    print('\n'.join(map(str, (S[p - 1][q - 1] for p, q in (map(int, e.split()) for e in s[M + 1:])))))
if __name__ == '__main__':
    main()

Verdicts: Wrong Answer

Accepted
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):

import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

def lunlun_num(N):
    N = str(N)
    L = len(N)

    dp = [[0]*10 for j in range(L)]
    for j in range(1,int(N[0])):
        dp[0][j] = 1

    flag = True
    for i in range(L-1):
        d = int(N[i+1])
        b = int(N[i])
        
        dp[i+1][0] += dp[i][0] + dp[i][1]
        dp[i+1][9] += dp[i][8] + dp[i][9]
        for j in range(1,9):
            dp[i+1][j] += dp[i][j-1] + dp[i][j] + dp[i][j+1]
        for j in range(1,10):
            dp[i+1][j] += 1

        if flag:
            if d < b - 1:
                flag = False
            elif d <= b + 1:
                for j in range(max(0, b-1),d):
                    dp[i+1][j] += 1
            else:
                for j in range(max(0, b-1),b+2):
                    dp[i+1][j] += 1
                    flag = False

    return sum(dp[L-1]) + 1 if flag else sum(dp[L-1])


def main():
    K = int(readline())

    
    left = 0
    right = 10**10
    while left + 1 < right:
        x = (left + right) // 2

        if lunlun_num(x) >= K:
            right = x
        else:
            left = x
    
    print(right)


if __name__ == "__main__":
    main()



from itertools import accumulate
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

def main():
    N,M,Q,*lr = map(int, read().split())

    LR = [[0]*(N+1) for _ in range(N+1)]
    query = []
    for i, (l, r) in enumerate(zip(*[iter(lr)]*2)):
        if i < M:
            LR[l][r] += 1
        else:
            query.append((l, r))
    
    for i in range(1,N+1):
        LR[1][i] += LR[1][i-1]
        LR[i][1] += LR[i-1][1]
    
    for i in range(2, N+1):
        for j in range(2,N+1):
            LR[i][j] += LR[i-1][j] + LR[i][j-1] - LR[i-1][j-1]
    
    for p, q in query:
        ans = LR[q][q] - LR[p-1][q] - LR[q][p-1] + LR[p-1][p-1]
        print(ans)


if __name__ == "__main__":
    main()


Verdicts: Runtime Error

Accepted
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):
import numpy as np

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

lrs = [list(map(int, input().split())) for _ in range(m)]
pqs = [list(map(int, input().split())) for _ in range(q)]

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

for lr in lrs:
    train_array[lr[0]-1][lr[1]-1] +=1


#print(train_array)

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

for index, train_vector in enumerate(train_array):
    train_array_ruisekiwa[index][0] = train_vector[0]

    for i in range(1, n):
        train_array_ruisekiwa[index][i] = train_array_ruisekiwa[index][i-1] + train_vector[i]

#print(train_array_ruisekiwa)

for pq in pqs:
    ans = 0
    for i in range(pq[0]-1,pq[1]):
        ans += train_array_ruisekiwa[i][pq[1] - 1] - train_array_ruisekiwa[i][pq[0] - 1]

    print(ans)

import numpy as np
import sys

input=sys.stdin.readline

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

lrs = [list(map(int, input().split())) for _ in range(m)]
pqs = [list(map(int, input().split())) for _ in range(q)]

train_array = np.zeros((n+1,n+1),dtype=int)

for lr in lrs:
    train_array[lr[0]][lr[1]] +=1


print(train_array)

train_array_ruisekiwa = np.zeros((n+1,n+1), dtype = int)

for index, train_vector in enumerate(train_array):
    train_array_ruisekiwa[index][0] = train_vector[0]

    for i in range(1, n+1):
        train_array_ruisekiwa[index][i] = train_array_ruisekiwa[index][i-1] + train_vector[i]

print(train_array_ruisekiwa)

for pq in pqs:
    ans = 0
    for i in range(pq[0],pq[1]+1):
        ans += train_array_ruisekiwa[i][pq[1]] - train_array_ruisekiwa[i][pq[0] - 1]

    print(ans)

import numpy as np
import sys

input=sys.stdin.readline

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

lrs = [list(map(int, input().split())) for _ in range(m)]
pqs = [list(map(int, input().split())) for _ in range(q)]

train_array = np.zeros((n+1,n+1),dtype=int)

for lr in lrs:
    train_array[lr[0]][lr[1]] +=1


#print(train_array)

train_array_ruisekiwa = np.zeros((n+1,n+1), dtype = int)

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

#print(train_array_ruisekiwa)

for pq in pqs:
    print(train_array_ruisekiwa[pq[1]][pq[1]] - train_array_ruisekiwa[pq[1]][pq[0]-1] - train_array_ruisekiwa[pq[0]-1][pq[1]] + train_array_ruisekiwa[pq[0]-1][pq[0]-1])



Verdicts: Wrong Answer

Wrong Answer

Accepted
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):
from itertools import accumulate
from operator import add, mul
n,m,q=map(int,input().split())

a=[]
b=[]
for i in range(n):
    a.append([0]*(n))
    b.append([0]*(n))

#import numpy as np
#b=np.array(b)
#print(a)
'''
for i in range(m):
    l,r=map(int,input().split())
    #print(a[(r-1):n,0:l])
    #a[(r-1):n,0:l]+=1
    for j in range(r-1,n):
        for k in range(l):
            a[j][k]+=1
'''
for i in range(m):
    l,r=map(int,input().split())
    #print(a[(r-1):n,0:l])
    a[l-1][r-1]+=1

#print(a)

for i in range(n):
    a[i]=list(accumulate(a[i]))

#print(a)

for i in range(n):
    for j in range(n-i):
        a[n-i-j-2][n-i-1]+=a[n-i-j-1][n-i-1]
        #print(a)

print(a)

'''
for l in range(n):
    for r in range(l,n):
        temp=a[r][l]
        for i in range(r,n):
            for j in range(0,l+1):
                b[i][j]+=temp
        #b[r:n,0:l+1]+=temp
'''
#print(a)
#print(b)

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


from itertools import accumulate
from operator import add, mul
n,m,q=map(int,input().split())

a=[]
b=[]
for i in range(n):
    a.append([0]*(n))
    b.append([0]*(n))

#import numpy as np
#b=np.array(b)
#print(a)
'''
for i in range(m):
    l,r=map(int,input().split())
    #print(a[(r-1):n,0:l])
    #a[(r-1):n,0:l]+=1
    for j in range(r-1,n):
        for k in range(l):
            a[j][k]+=1
'''
for i in range(m):
    l,r=map(int,input().split())
    #print(a[(r-1):n,0:l])
    a[l-1][r-1]+=1

#print(a)

for i in range(n):
    a[i]=list(accumulate(a[i]))

#print(a)

for i in range(n):
    for j in range(n-i-1):
        a[n-i-j-2][n-i-1]+=a[n-i-j-1][n-i-1]
        #print(a)

#print(a)

'''
for l in range(n):
    for r in range(l,n):
        temp=a[r][l]
        for i in range(r,n):
            for j in range(0,l+1):
                b[i][j]+=temp
        #b[r:n,0:l+1]+=temp
'''
#print(a)
#print(b)

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


Verdicts: Wrong Answer

Accepted
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())
T = [[0 for _ in range(N+1)] for _ in range(N+1)]
for i in range(M):
  L,R = map(int, input().split())
  T[L][R] += 1
pprint(T)
for l in range(1,N+1):
  for r in range(1,N+1):
    T[l][r] += T[l-1][r]+T[l][r-1]-T[l-1][r-1]
ans = []
pprint(T)
for i in range(Q):
  p,q = map(int, input().split())
  ans.append(T[p-1][p-1]+T[q][q]-T[p-1][q]-T[q][p-1])
print('\n'.join(map(str,ans)))
quit()


N,M,Q = map(int,input().split())
T = [[0 for _ in range(N+1)] for _ in range(N+1)]
for i in range(M):
  L,R = map(int, input().split())
  T[L][R] += 1
for l in range(1,N+1):
  for r in range(1,N+1):
    T[l][r] += T[l-1][r]+T[l][r-1]-T[l-1][r-1]
ans = []
for i in range(Q):
  p,q = map(int, input().split())
  ans.append(T[p-1][p-1]+T[q][q]-T[p-1][q]-T[q][p-1])
print('\n'.join(map(str,ans)))


Verdicts: Runtime Error

Accepted
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):

def f(h,w,a):
    da = [[0]*w for _ in range(h)]
    da[0][0] = a[0][0]
    for i in range(1, w):
        da[0][i] = da[0][i-1] + a[0][i]
    for i in range(1, h):
        cnt_w = 0
        for j in range(w):
            cnt_w += a[i][j]
            da[i][j] = da[i-1][j] + cnt_w
    return da

def Calc(p,q,x,y, da):
    if p>x  or q>y:
        return 0
    if p==0 or q==0:
        return da[x][y]
    if p==0:
        return da[x][y] - da[x][q-1]
    if q==0:
        return da[x][y] - da[p-1][y]
    return da[x][y] - da[x][q-1] - da[p-1][y] + da[p-1][q-1]

N,M,Q = map(int,input().split())
t = [[0]*(N+1) for _ in range(N+1)]
for _ in range(M):
    l,r = map(int,input().split())
    t[l][r] += 1

d = f(N,N,t)
query = []
for _ in range(Q):
    p,q = map(int,input().split())
    p -= 1
    q -= 1
    print(Calc(p,p,q,q,d))

def f(h,w,a):
    da = [[0]*(w+1)for _ in range(h+1)]
    da[0][0] = a[0][0]
    for i in range(1, w+1):
        da[0][i] = da[0][i-1] + a[0][i]
    for i in range(1, h+1):
        cnt_w = 0
        for j in range(w+1):
            cnt_w += a[i][j]
            da[i][j] = da[i-1][j] + cnt_w
    return da

def Calc(p,q,x,y, da):
    if p>x  or q>y:
        return 0
    if p==0 or q==0:
        return da[x][y]
    if p==0:
        return da[x][y] - da[x][q-1]
    if q==0:
        return da[x][y] - da[p-1][y]
    return da[x][y] - da[x][q-1] - da[p-1][y] + da[p-1][q-1]

N,M,Q = map(int,input().split())
t = [[0]*(N+1) for _ in range(N+1)]
for _ in range(M):
    l,r = map(int,input().split())
    t[l][r] += 1

d = f(N,N,t)
for _ in range(Q):
    p,q = map(int,input().split())
    print(Calc(p,p,q,q,d))

Verdicts: Wrong Answer

Accepted
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 = [list(map(int, input().split())) for i in range(M)]
PQ = [list(map(int, input().split())) for i in range(Q)]

acc = [[0 for i in range(N+1)] for i in range(N+1)]  
coordinate = [[0 for i in range(N)] for i in range(N)]
for l, r in LR:
    l -= 1
    r -= 1
    coordinate[l][r] += 1

for i in range(N):
    for j in range(N):
        acc[i+1][j+1] = acc[i][j+1] + acc[i+1][j] - acc[i][j] + coordinate[i][j]
print(acc)
for p, q in PQ:
    p -= 1
    ans = acc[N][q] - acc[p][q]
    print(ans)

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)]

acc = [[0 for i in range(N+1)] for i in range(N+1)]  
coordinate = [[0 for i in range(N)] for i in range(N)]
for l, r in LR:
    l -= 1
    r -= 1
    coordinate[l][r] += 1

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

for p, q in PQ:
    p -= 1
    ans = acc[N][q] - acc[p][q]
    print(ans)

Verdicts: Wrong Answer

Accepted
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):
# coding:utf-8
n,m,q=map(int,input().split())
dp = [[0 for i in range(n)] for j in range(n)]
for i in range(m):
    l,r=map(int,input().split())
    l-=1
    r-=1
    dp[l][r]+=1
for i in range(n):
    for j in range(n-1):
        dp[i][j+1]+=dp[i][j]
for j in range(n):
    for i in range(n-1,0,-1):
        dp[i-1][j]+=dp[i][j]
print(dp)
for i in range(n):
    p,q=map(int,input().split())
    p-=1
    q-=1
    if q==n-1:
        print(dp[p][q])
    else :
     print(dp[p][q]-dp[q][q])


# coding:utf-8
n,m,qq=map(int,input().split())
dp = [[0 for i in range(n+5)] for j in range(n+5)]
for i in range(m):
    l,r=map(int,input().split())
    l-=1
    r-=1
    dp[l][r]+=1
for i in range(n):
    for j in range(n-1):
        dp[i][j+1]+=dp[i][j]
for j in range(n):
    for i in range(n-1,0,-1):
        dp[i-1][j]+=dp[i][j]
for i in range(qq):
    p,q=map(int,input().split())
    p-=1
    q-=1
    if q==n-1:
        print(dp[p][q])
    else :
     print(dp[p][q]-dp[q+1][q])


Verdicts: Runtime Error

Accepted
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())
alist=[]
for i in range(m):
    l,r=map(int,input().split())
    alist.append([l,r])
for t in range(q):
    count=m
    p,q=map(int,input().split())
    for i in alist:
        if p>i[0] or p<i[1]:
            count-=1
    print(count)

n,m,q=map(int,input().split())
alist=[]
for i in range(m):
    l,r=map(int,input().split())
    alist.append([l,r])
alist.sort()
for t in range(q):
    count=0
    blist=[]
    p,q=map(int,input().split())
    print(alist)
    for j in range (len(alist)):
        if p<=alist[0][0]:
            alist.sort(key=lambda x:x[1])
            break
        blist.append(alist[0])
        alist.remove(alist[0])
    for j in range (len(alist)):
        if q>=alist[j][1]:
            count+=1
        else:
            break
    for k in blist:
        alist.append(k)
    print(count)
    alist.sort(key=lambda x:x[0])

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

rui = [[0 for _ in range(n + 1)] for _ in range(n + 1)]
for i in range(1, n + 1):
    for j in range(1, n + 1):
        rui[i][j] = lr[i][j] + rui[i - 1][j] + rui[i][j - 1] - rui[i - 1][j - 1]
    
for _ in range(Q):
    p, q = map(int, input().split())
    p -= 1
    ans = rui[q][q] - rui[p][q] - rui[q][p] + rui[p][p]
    print(ans)

Verdicts: Wrong Answer

Wrong Answer

Accepted
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())
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]
print(trains)
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)

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)

Verdicts: Wrong Answer

Accepted