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



Sample input:
2 3 1
1 1
1 2
2 2
1 2


Sample output:
3

Submission status: Wrong Answer

Solution code:
N,M,Q=map(int,input().split())
Town=[[int(i) for i in input().split()] for i in range(M)]
Town.sort(key=lambda x:x[0])

def BS_left(x,L,s):
  L_copy=L[:]
  left=0
  if L[s-1]<x:
    return s-1
  else:
    while s>2:
      if L_copy[s//2]<x:
        L_copy=L_copy[s//2:s]
        left+=s//2
        s=s-s//2
      else:
        L_copy=L_copy[0:s//2+1]
        s=s//2+1
    if L[left]>=x:
      return left-1
    else:
      return left

def BS_right(x,L,s):
  L_copy=L[:]
  right=s-1
  if L[0]>x:
    return 0
  else:
    while s>2:
      if L_copy[s//2]<=x:
        L_copy=L_copy[s//2:s]
        s=s-s//2
      else:
        L_copy=L_copy[0:s//2+1]
        right+=-s//2+1
        s=s//2+1
    if L[right]<=x:
      return right+1
    else:
      return right

ans=[0]*Q
for i in range(Q):
  p,q=map(int,input().split())
  for i in zip(*Town):
    TownL=i
    break
  a=BS_left(p,TownL,M)+1
  newTown=Town[a:]
  if M-a==0:
    print(0)
  else:
    newTown.sort(key=lambda x:x[1])
    e=0
    for i in zip(*newTown):
      if e==0:
        e+=1
      else:
        TownR=i
        break
    b=BS_right(q,TownR,M-a)
    if b==1 and TownR[0]>q:
      print(0)
    else:
      print(b-1)

Submission status: Wrong Answer

Solution code:
N,M,Q=map(int,input().split())
Town=[[int(i) for i in input().split()] for i in range(M)]
Town.sort(key=lambda x:x[0])

def BS_left(x,L,s):
  L_copy=L[:]
  left=0
  if L[s-1]<x:
    return s-1
  else:
    while s>2:
      if L_copy[s//2]<x:
        L_copy=L_copy[s//2:s]
        left+=s//2
        s=s-s//2
      else:
        L_copy=L_copy[0:s//2+1]
        s=s//2+1
    if L[left]>=x:
      return left-1
    else:
      return left

def BS_right(x,L,s):
  L_copy=L[:]
  right=s-1
  if L[0]>x:
    return 0
  else:
    while s>2:
      if L_copy[s//2]<=x:
        L_copy=L_copy[s//2:s]
        s=s-s//2
      else:
        L_copy=L_copy[0:s//2+1]
        right+=-s//2+1
        s=s//2+1
    if L[right]<=x:
      return right+1
    else:
      return right

ans=[0]*Q
for i in range(Q):
  p,q=map(int,input().split())
  for i in zip(*Town):
    TownL=i
    break
  a=BS_left(p,TownL,M)+1
  b=BS_right(q,TownL,M)
  newTown=Town[a:b]
  if b-a==0:
    print(0)
  else:
    newTown.sort(key=lambda x:x[1])
    e=0
    for i in zip(*newTown):
      if e==0:
        e+=1
      else:
        TownR=i
        break
    c=BS_right(q,TownR,b-a)
    if c==1 and TownR[0]>q:
      print(0)
    else:
      print(1+c)

Submission status: Wrong Answer

Solution code:
N,M,Q=map(int,input().split())
Town=[[int(i) for i in input().split()] for i in range(M)]
Town.sort(key=lambda x:x[0])

def BS_left(x,L,s):
  L_copy=L[:]
  left=0
  if L[s-1]<x:
    return s-1
  else:
    while s>2:
      if L_copy[s//2]<x:
        L_copy=L_copy[s//2:s]
        left+=s//2
        s=s-s//2
      else:
        L_copy=L_copy[0:s//2+1]
        s=s//2+1
    if L[left]>=x:
      return left-1
    else:
      return left

def BS_right(x,L,s):
  L_copy=L[:]
  right=s-1
  if L[0]>x:
    return 0
  else:
    while s>2:
      if L_copy[s//2]<=x:
        L_copy=L_copy[s//2:s]
        s=s-s//2
      else:
        L_copy=L_copy[0:s//2+1]
        right+=-s//2+1
        s=s//2+1
    if L[right]<=x:
      return right+1
    else:
      return right

ans=[0]*Q
for i in range(Q):
  p,q=map(int,input().split())
  TownL=list(zip(*Town))[0]
  a=BS_left(p,TownL,M)+1
  b=BS_right(q,TownL,M)
  newTown=Town[a:b]
  if b-a==0:
    print(0)
  else:
    newTown.sort(key=lambda x:x[1])
    TownR=list(zip(*newTown))[1]
    c=BS_right(q,TownR,b-a)
    if c==1 and TownR[0]>q:
      print(0)
    else:
      print(c-1)

Submission status: Wrong Answer

Solution code:
N,M,Q=map(int,input().split())
Town=[[int(i) for i in range(M)]]
Town.sort(key=lambda x:x[0])

def BS_left(x,L):
  L_copy=L[:]
  l=len(L_copy)
  left=0
  if L[l-1]<x:
    return l-1
  else:
    while l>2:
      if L_copy[l//2]<x:
        L_copy=L_copy[l//2:l]
        left+=l//2
      else:
        L_copy=L_copy[0:l//2+1]
      l=len(L_copy)
    if L[left]>=x:
      return left-1
    else:
      return left

def BS_right(x,L):
  L_copy=L[:]
  l=len(L_copy)
  right=l-1
  if L[0]>x:
    return 0
  else:
    while l>2:
      if L_copy[l//2]<=x:
        L_copy=L_copy[l//2:l]
      else:
        L_copy=L_copy[0:l//2+1]
        right+=-l//2+1
      l=len(L_copy)
    if L[right]<=x:
      return right+1
    else:
      return right

ans=[0]*Q
for i in range(Q):
  p,q=map(int,input().split())
  TownL=list(zip(*Town))[0]
  newTown=Town[BS_left(p,TownL)+1:BS_right(q,TownL)]
  if len(newTown)==0:
    print(0)
  else:
    newTown.sort(key=lambda x:x[1])
    TownR=list(zip(*newTown))[1]
    if BS_right(q,TownR)==1 and TownR[0]>q:
      print(0)
    else:
      print(BS_right(q,TownR))

Submission status: Wrong Answer

Solution code:
N,M,Q=map(int,input().split())
Town=[[0,0] for i in range(M)]
for i in range(M):
  Town[i][0],Town[i][1]=map(int,input().split())
Town.sort(key=lambda x:x[0])

def BS_left(x,L):
  L_copy=L[:]
  l=len(L_copy)
  left=0
  if L[l-1]<x:
    return l-1
  else:
    while l>2:
      if L_copy[l//2]<x:
        L_copy=L_copy[l//2:l]
        left+=l//2
      else:
        L_copy=L_copy[0:l//2+1]
      l=len(L_copy)
    if L[left]>=x:
      return left-1
    else:
      return left

def BS_right(x,L):
  L_copy=L[:]
  l=len(L_copy)
  right=l-1
  if L[0]>x:
    return 0
  else:
    while l>2:
      if L_copy[l//2]<=x:
        L_copy=L_copy[l//2:l]
      else:
        L_copy=L_copy[0:l//2+1]
        right+=-l//2+1
      l=len(L_copy)
    if L[right]<=x:
      return right+1
    else:
      return right

ans=[0]*Q
for i in range(Q):
  p,q=map(int,input().split())
  TownL=list(zip(*Town))[0]
  newTown=Town[BS_left(p,TownL)+1:BS_right(q,TownL)]
  if len(newTown)==0:
    print(0)
  else:
    newTown.sort(key=lambda x:x[1])
    TownR=list(zip(*newTown))[1]
    if BS_right(q,TownR)==1 and TownR[0]>q:
      print(0)
    else:
      print(BS_right(q,TownR)-1)

Submission status: Wrong Answer

Solution code:
N,M,Q=map(int,input().split())
Town=[[0,0] for i in range(M)]
for i in range(M):
  Town[i][0],Town[i][1]=map(int,input().split())
Town.sort(key=lambda x:x[0])

def BS_left(x,L):
  L_copy=L[:]
  l=len(L_copy)
  left=0
  while l>2:
    if L_copy[l//2]<x:
      L_copy=L_copy[l//2:l]
      left+=l//2
    else:
      L_copy=L_copy[0:l//2+1]
    l=len(L_copy)
  if L[left]>=x:
    return left-1
  else:
    return left

def BS_right(x,L):
  L_copy=L[:]
  l=len(L_copy)
  right=l-1
  while l>2:
    if L_copy[l//2]<=x:
      L_copy=L_copy[l//2:l]
    else:
      L_copy=L_copy[0:l//2+1]
      right+=-l//2+1
    l=len(L_copy)
  if L[right]<=x:
    return right+1
  else:
    return right

ans=[0]*Q
for i in range(Q):
  p,q=map(int,input().split())
  TownL=list(zip(*Town))[0]
  newTown=Town[BS_left(p,TownL)+1:BS_right(q,TownL)]
  if len(newTown)==0:
    print(0)
  else:
    newTown.sort(key=lambda x:x[1])
    TownR=list(zip(*newTown))[1]
    if BS_right(q,TownR)==1 and TownR[0]>q:
      print(0)
    else:
      print(BS_right(q,TownR))

Submission status: Wrong Answer

Solution code:
N,M,Q=map(int,input().split())
Town=[[0,0] for i in range(M)]
for i in range(M):
  Town[i][0],Town[i][1]=map(int,input().split())
Town.sort(key=lambda x:x[0])

def BS_left(x,L):
  L_copy=L[:]
  l=len(L_copy)
  left=0
  while l>2:
    if L_copy[l//2]<x:
      L_copy=L_copy[l//2:l]
      left+=l//2
    else:
      L_copy=L_copy[0:l//2+1]
    l=len(L_copy)
  if L[left]>=x:
    return left-1
  else:
    return left

def BS_right(x,L):
  L_copy=L[:]
  l=len(L_copy)
  right=l-1
  while l>2:
    if L_copy[l//2]<=x:
      L_copy=L_copy[l//2:l]
    else:
      L_copy=L_copy[0:l//2+1]
      right+=-l//2+1
    l=len(L_copy)
  if L[right]<=x:
    return right+1
  else:
    return right

ans=[0]*Q
for i in range(Q):
  p,q=map(int,input().split())
  TownL=list(zip(*Town))[0]
  newTown=Town[BS_left(p,TownL)+1:BS_right(q,TownL)]
  newTown.sort(key=lambda x:x[1])
  TownR=list(list(zip(*newTown))[1])
  if BS_right(q,TownR)==1 and TownR[0]>q:
    print(0)
  else:
    print(BS_right(q,TownR))

Submission status: Wrong Answer

Solution code:
N,M,Q=map(int,input().split())
Town=[[0,0] for i in range(M)]
for i in range(M):
  Town[i][0],Town[i][1]=map(int,input().split())
Town.sort(key=lambda x:x[0])

def BS_left(x,L):
  L_copy=L[:]
  l=len(L_copy)
  left=0
  while l>2:
    if L_copy[l//2]<x:
      L_copy=L_copy[l//2:l]
      left+=l//2
    else:
      L_copy=L_copy[0:l//2+1]
    l=len(L_copy)
  if L[left]>=x:
    return left-1
  else:
    return left

def BS_right(x,L):
  L_copy=L[:]
  l=len(L_copy)
  right=l-1
  while l>2:
    if L_copy[l//2]<=x:
      L_copy=L_copy[l//2:l]
    else:
      L_copy=L_copy[0:l//2+1]
      right+=-l//2+1
    l=len(L_copy)
  if L[right]<=x:
    return right+1
  else:
    return right

ans=[0]*Q
for i in range(Q):
  p,q=map(int,input().split())
  TownL=list(list(zip(*Town))[0])
  newTown=Town[BS_left(p,TownL)+1:BS_right(q,TownL)]
  newTown.sort(key=lambda x:x[1])
  TownR=list(list(zip(*newTown))[1])
  ans[i]=BS_right(q,TownR)
  print(ans[i])

Submission status: Wrong Answer

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

memo = [[0 for _ in range(N)] for _ in range(N)]
for l, r in LR:
    memo[l - 1][r - 1] += 1
[print(_) for _ in memo]
for p, q in pq:
    print(sum([sum(memo[_][p - 1:q]) for _ in range(p - 1, q)]))

Submission status: Wrong Answer

Solution code:
def m():
    n, M, Q = map(int, input().split())
    L, R = 0, 1
    a = [[0 for _ in range(n+1)] for _ in range(2)]
    for i in range(M):
        l, r = map(int, input().split())
        a[L][l] += 1
        a[R][r] += 1
    b = [[0 for _ in range(n+1)] for _ in range(2)]

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

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

Submission status: Wrong Answer

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

Map = [ [0 for i in range(N)] for j in range(N)]
for i in range(M):
    l,r=map(int,raw_input().split())
    Map[l-1][r-1]=1

c = []
for i in range(N):
    cc=[]
    cc_v=0
    for j in range(N):
        cc_v+=Map[i][j]
        cc.append(cc_v)
    c.append(cc)

for i in range(Q):
    p,q = map(int,raw_input().split())
    count=0    
    for j in range(p-1,q):
        if p!=1:
            count+=c[j][q-1]-c[j][p-2]
        else:
            count+=c[j][q-1]
    print count

Submission status: Wrong Answer

Solution code:
import numpy as np
N, M, Q = map(int, input().split())
trains = np.array([list(map(int, input().split())) for _ in range(M)])
questions = np.array([list(map(int, input().split())) for _ in range(Q)])
for q in questions:
    count = 0
    for t in trains:
        if np.any(q <= t) and np.any(q >= t):
            count += 1
    print(count)

Submission status: Wrong Answer

Solution code:
n,m,q= map(int,input().split())
l= [input().rstrip().split() for i in range(0,m)]
p = [input().rstrip().split() for i in range(0,q)]

l.sort()
l.reverse()

u =[0]*q
for i in range(0,q):
    cnt = 0
    for j in range(0,m):
        if int(p[i][0])>int(l[j][0]):
            break
        if (int(p[i][0])<=int(l[j][0])) and (int(p[i][1])>=int(l[j][1])):
            # print(p[i][0],p[i][1],l[j][0],l[j][1])
            cnt+=1
    u[i] = cnt

for i in range(0,q):
    print(u[i])

Submission status: Wrong Answer

Solution code:
n,m,q= map(int,input().split())
l= [input().rstrip().split() for i in range(0,m)]
p = [input().rstrip().split() for i in range(0,q)]


u =[0]*q
for i in range(0,q):
    cnt = 0
    for j in range(0,m):
        if (int(p[i][0])<=int(l[j][0])) and (int(p[i][1])>=int(l[j][1])):
            print(p[i][0],p[i][1],l[j][0],l[j][1])
            cnt+=1
    u[i] = cnt
    
for i in range(0,q):
    print(u[i])

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

Solution code:
from bisect import bisect_left
def main():
	n, m, q = list(map(int, input().split()))
	trains = [list(map(int, input().split())) for _ in range(m)]
	queries = [list(map(int, input().split())) for _ in range(q)]
	
	trains.sort()	
	frms = [x[0] for x in trains]
	tos = [x[1] for x in trains]

	for query in queries:
		start = bisect_left(frms, query[0])
		end = bisect_left(tos, query[1] + 1)
		print(end - start)

if __name__ == '__main__':
	main()

Submission status: Wrong Answer

Solution code:
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)

Submission status: Wrong Answer

Solution code:
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)

Submission status: Wrong Answer

Solution code:
N,M,Q = map(int,raw_input().split())
a = []
for i in range(M):
  b = map(int,raw_input().split())
  a.append(b)
for i in range(Q):
  c,d = map(int,raw_input().split())
  x = 0
  for j in range(Q):
    e = a[j]
    if c <= int(e[0]) and d >= int(e[1]):
      x += 1
  print x

Submission status: Wrong Answer

Solution code:
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)

Submission status: Wrong Answer

Solution code:
N, M, Q = list(map(int, input().split()))
L = [0 for i in range(M)]
R = L
p = [0 for i in range(Q)]
q = p
for i in range(M):
  L[i], R[i] = list(map(int, input().split()))
for i in range(Q):
  p[i], q[i] = list(map(int, input().split()))

for i in range(Q):
  count = 0
  for j in range(M):
    if p[i] <= L[j] and R[j] <= q[i]:
      count += 1
  print(count)

Submission status: Wrong Answer

Solution code:
# input
N, M, Q = map(int, input().split())
train_query = {} # 対象区間とクエリを一緒にソート
for i in range(M + Q):
    train_query[i] = list(map(int, input().split()))

train_query = sorted(train_query.items(), key=lambda x: x[1][1])
# 辞書をソートするとリストが返ってくることに注意

a = [0 for _ in range(N)]

for j in range(M + Q):
    if train_query[j][0] < M: # 対象区間
        a[train_query[j][1][0] - 1] += 1
    else: # クエリ
        ans = sum(a[(train_query[j][1][0] - 1):(train_query[j][1][1])])
        print(ans)

Submission status: Wrong Answer

Solution code:
# input
N, M, Q = map(int, input().split())
train_query = {} # 対象区間とクエリを一緒にソート
for i in range(M + Q):
    train_query[i] = list(map(int, input().split()))

train_query = sorted(train_query.items(), key=lambda x: x[1][1])
print(train_query)
# 辞書をソートするとリストが返ってくることに注意

a = [0 for _ in range(N)]

for j in range(M + Q):
    if train_query[j][0] < M: # 対象区間
        a[train_query[j][1][0] - 1] += 1
    else: # クエリ
        ans = sum(a[(train_query[j][1][0] - 1):(train_query[j][1][1])])
        print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
n,m,q=map(int,input().split())
a=np.zeros((n+2,n+2))
for i in range(m):
  s,e=map(int,input().split())
  a[:s,e:]+=1
print(a)
for i in range(q):
  s,e=map(int,input().split())
  print(a[s,e])

Submission status: Wrong Answer

Solution code:
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
#        for i in range(L):
#            for j in range(N - R + 1):
#                d[i][R + j - 1] += 1
        counter -= 1
        if counter == 0:
#            print(d)
            for i in range(N):
                d[i] = d[i][::-1]
#            print(d)
            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]

Submission status: Wrong Answer

Solution code:
import numpy as np

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

mp = np.zeros((N+1,N+1), dtype='int32')

for _ in range(M):
    l1, l2 = map(int, input().split())
    mp[l1, l2] += 1

cumsum_mp = np.cumsum(np.cumsum(mp, axis=1), axis=0)

for _ in range(Q):
    p1, p2 = map(int, input().split())
    if p1 == 1:
        print(cumsum_mp[p2][p2])
    else:
        print(cumsum_mp[p2][p2] - cumsum_mp[p1][p2-1] - cumsum_mp[p2-1][p1] + cumsum_mp[p1][p1])

Submission status: Wrong Answer

Solution code:
import numpy as np

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

mp = np.zeros((N+1,N+1), dtype='int32')

for _ in range(M):
    l1, l2 = map(int, input().split())
    mp[l1, l2] += 1

cumsum_mp = np.cumsum(np.cumsum(mp, axis=1), axis=0)

for _ in range(Q):
    p1, p2 = map(int, input().split())
    if p1 == 1:
        print(cumsum_mp[p2][p2])
    else:
        print(cumsum_mp[p2][p2] - cumsum_mp[p1-1][p2] - cumsum_mp[p2][p1-1] + cumsum_mp[p1][p1])

Submission status: Wrong Answer

Solution code:
import numpy as np

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

mp = np.zeros((N+1,N+1), dtype='int32')

for _ in range(M):
    l1, l2 = map(int, input().split())
    mp[l1, l2] += 1

cumsum_mp = np.cumsum(np.cumsum(mp, axis=1), axis=0)

for _ in range(Q):
    p1, p2 = map(int, input().split())
    if p1 == 1:
        print(cumsum_mp[p2][p2])
    else:
        print(cumsum_mp[p1][p1] - cumsum_mp[p1][p2] + cumsum_mp[p2][p2] - cumsum_mp[p2][p1])

Submission status: Wrong Answer

Solution code:
import numpy as np

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

mp = np.zeros((N+1,N+1), dtype='int32')

for _ in range(M):
    l1, l2 = map(int, input().split())
    mp[l1, l2] += 1

cumsum_mp = np.cumsum(np.cumsum(mp, axis=1), axis=0)
print(cumsum_mp)

for _ in range(Q):
    p1, p2 = map(int, input().split())
    if p1 == 1:
        print(cumsum_mp[p2][p2])
    else:
        print(cumsum_mp[p1][p1] - cumsum_mp[p1][p2] + cumsum_mp[p2][p2] - cumsum_mp[p2][p1])

Submission status: Wrong Answer

Solution code:
from collections import Counter
from itertools import product
import numpy as np

n,m,q  = map(int,input().split())
rails=[tuple(map(int,input().split())) for i in range(m)]
qs=[tuple(map(int,input().split())) for i in range(q)]

xlist = np.array([[0 for j in range(n)] for i in range(n)])
for (l,r),i in Counter(rails).items():
    xlist[l-1,r-1]=i

sumsumlist = np.cumsum(np.cumsum(xlist,axis=1),axis=0)

print(xlist)
print(sumsumlist)

for (p,q) in qs:
    if p>1:
        ans = sumsumlist[q-1][q-1] - sumsumlist[q-1][p-2] - sumsumlist[p-2][q-1] + sumsumlist[p-2][p-2]
    elif p==1:
        ans = sumsumlist[q-1][q-1]

    print(ans)

Submission status: Wrong Answer

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

    express_list = []
    for _ in range(M):
        express_list.append(list(map(int, input().split())))

    question_list = []
    for _ in range(Q):
        question_list.append(list(map(int, input().split())))

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

    for l in express_list:
        l1, l2 = l[:]
        n_list[l1][l2] += 1

    for l in n_list:
        print(l)

    for q in question_list:
        ans = 0

        p1, p2 = q[:]

        n_exp = 0
        for i in range(p1, p2+1):
            n_exp += sum(n_list[i][1:p2+1])

        print(n_exp)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
#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))

Submission status: Wrong Answer

Solution code:
#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))

Submission status: Wrong Answer

Solution code:
import numpy as np


def LI(): return list(map(int, input().split()))
def LI_(): return list(map(lambda x: int(x) - 1, input().split()))


def cumulative_sum_ref(d1_array):
    for i in range(1, len(d1_array)):
        d1_array[i] += d1_array[i-1]


def cumulative_sum_val(d1_array):
    tmp = d1_array.copy()
    for i in range(1, len(tmp)):
        tmp[i] += tmp[i-1]
    return tmp


# 累積和の計算方法が遅すぎるっぽい。
if __name__ != "__main__":
    N, M, Q = LI()
    LR = np.zeros((N+1, N+1), dtype='uint32')
    for i in range(M):
        l, r = LI()
        LR[l][r] += 1

    # 二次元累積和
    for i in range(1, N+1):
        for j in range(2, N+1):
            LR[i][j] += LR[i][j-1]
    for i in range(1, N+1):
        for j in range(2, N+1):
            LR[j][i] += LR[j-1][i]

    for _ in range(Q):
        p, q = LI()
        p -= 1
        result = LR[q][q] - LR[p][q] - LR[q][p] + LR[p][p]
        print(result)


if __name__ == "__main__":
    N, M, Q = LI()
    LR = np.zeros((N+1, N+1), dtype='uint32')
    for i in range(M):
        l, r = LI()
        LR[l][r] += 1

    # 二次元累積和
    for i in range(1, N+1):
        for j in range(2, N+1):
            LR[i][j] += LR[i][j-1]
            LR[i][j] += LR[i-1][j]
            LR[i][j] -= LR[i-1][j-1]

    for _ in range(Q):
        p, q = LI()
        p -= 1
        result = LR[q][q] - LR[p][q] - LR[q][p] + LR[p][p]
        print(result)

Submission status: Wrong Answer

Solution code:
import numpy as np


def LI(): return list(map(int, input().split()))
def LI_(): return list(map(lambda x: int(x) - 1, input().split()))


def cumulative_sum_ref(d1_array):
    for i in range(1, len(d1_array)):
        d1_array[i] += d1_array[i-1]


def cumulative_sum_val(d1_array):
    tmp = d1_array.copy()
    for i in range(1, len(tmp)):
        tmp[i] += tmp[i-1]
    return tmp


# 累積和の計算方法が遅すぎるっぽい。
if __name__ != "__main__":
    N, M, Q = LI()
    LR = np.zeros((N+1, N+1), dtype='uint32')
    for i in range(M):
        l, r = LI()
        LR[l][r] += 1

    # 二次元累積和
    for i in range(1, N+1):
        for j in range(2, N+1):
            LR[i][j] += LR[i][j-1]
    for i in range(1, N+1):
        for j in range(2, N+1):
            LR[j][i] += LR[j-1][i]

    for _ in range(Q):
        p, q = LI()
        p -= 1
        result = LR[q][q] - LR[p][q] - LR[q][p] + LR[p][p]
        print(result)


if __name__ == "__main__":
    N, M, Q = LI()
    LR = np.zeros((N+1, N+1), dtype='uint32')
    for i in range(M):
        l, r = LI()
        LR[l][r] += 1

    # 二次元累積和
    for i in range(1, N+1):
        for j in range(2, N+1):
            LR[i][j] += LR[i][j-1]
            LR[i][j] += LR[i-1][j]
            LR[i][j] += LR[i-1][j-1]

    for _ in range(Q):
        p, q = LI()
        p -= 1
        result = LR[q][q] - LR[p][q] - LR[q][p] + LR[p][p]
        print(result)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sat Aug 18 21:50:39 2018
ABC106D
@author: maezawa
"""

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

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

for i in range(m):
    li, ri = list(map(int, input().split()))
    lr[li][ri] += 1
    
for i in range(n+1):
    for j in range(n):
        lr[i][j+1] += lr[i][j]
for i in range(n+1):
    for j in range(n):
        lr[j+1][i] += lr[j][i]

for _ in range(qn):
    pi, qi = list(map(int, input().split()))
    ans = lr[qi][qi] - lr[qi][pi-1] - lr[pi-1][qi]
    
    print(ans)

Submission status: Wrong Answer

Solution code:
import sys

ns = lambda: sys.stdin.readline().rstrip()
ni = lambda: int(ns())
na = lambda: [int(x) for x in ns().split()]
nall = lambda: [int(x) for x in sys.stdin.readlines()]


def main():
    n, m, q = na()
    lrs = [na() for _ in range(m)]
    pqs = [na() for _ in range(q)]

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

    for l, r in lrs:
        table[l][r] += 1

    # 行方向の累積和
    for i in range(n+1):
        for j in range(n+1):
            table[i][j] += table[i][j-1]

    # 列方向の累積和
    for j in range(n+1):
        for i in range(n+1):
            table[i][j] += table[i-1][j]
            
    for p, q in pqs:
        v = table[q][q] - table[p-1][q] - table[p][q-1] + table[p-1][p-1]
        print(v)
    

main()

Submission status: Wrong Answer

Solution code:
t,r,q = map(int,input().split())
R = []
Q = []

for _ in range(r):
    x = list(map(int,input().split()))
    R.append(x)

R.sort(key=lambda x:(x[0],x[1]))

for _ in range(q):
    x = list(map(int,input().split()))
    Q.append(x)

Q.sort(key=lambda x:(x[0],x[1]))

c = 0

for i in Q:
    if i[0] != c:
        R = [k for k in R if k[0] > c]
        c += 1
    a = 0
    for j in R:
        if i[0] <= j[0] <= j[1] <= i[1]:
            a += 1
    print(a)

Submission status: Wrong Answer

Solution code:
n, m, q = map(int, input().split())
a = []
for i in range(m):
    a.append(list(map(int, input().split())))
s = [0 for i in range(n+1)]
e = [0 for i in range(n+1)]

for i in range(m):
    s[a[i][0]] += 1
    e[a[i][1]] += 1

for i in range(1, n+1):
    s[i] += s[i-1]
    e[i] += e[i-1]

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

Submission status: Wrong Answer

Solution code:
import numpy as np

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

list1 = []
for i in range(M):
    L, R = map(int, input().split())
    list1.append([L, R])
    
list2 = []
for i in range(Q):
    p, q = map(int, input().split())
    list2.append([p, q])
    
mat = np.zeros((N+2,N+2))

for i in range(M):
    mat[list1[i][0],list1[i][1]] = 1

for i in range(Q):
    print(int(np.sum(mat[list2[i][0]:, :list2[i][1]+1])))

Submission status: Wrong Answer

Solution code:
n,m,q=map(int,input().split())
a = [set()]*(n+2)
for _ in range(m):
  l, r = map(int,input().split())
  for i in range(l,r+1): a[i].add(_)
for _ in range(q):
 p, q = map(int,input().split())
 ans = set()
 for i in range(p,q+1): ans = ans.union(a[i])
 print(len(ans))

Submission status: Wrong Answer

Solution code:
import itertools

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

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

acc_lr = []
for l in lr:
    acc_lr.append(list(itertools.accumulate(l)))

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

Submission status: Wrong Answer

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

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