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: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-

def main():
    n, m, qs = map(int, input().split())

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

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

    for p, q in pq_list:
        count = 0
        for l, r in lr_list:
            if p <= l and r <= q:
                count = count + 1
        print(count)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
n,m,q = input().split()
n = int(n)
m = int(m)
q = int(q)
kukan = []
kekka = []
for i in range(m):
    kukan.append(input().split())
    kukan[i][0] = int(kukan[i][0])
    kukan[i][1] = int(kukan[i][1])
for j in range(q):
    num = 0
    p,q = input().split()
    p = int(p)
    q = int(q)
    for k in range(m):
        if p <= kukan[k][0] and kukan[k][1] <= q:
            num += 1
        else:
            pass
    print(num)

Submission status: Time Limit Exceeded

Solution code:
N, M, Q = map(int, input().split())
LR =[[] for i in range(N)]
for i in range(M):
    L, R = map(int, input().split())
    LR[L-1].append(R)

ans = []
for i in range(Q):
    p, q = map(int, input().split())
    count = 0
    for j in range(p-1, q):
        for k in LR[j]:
            if k <= q:
                count += 1
    ans.append(count)

for i in range(len(ans)):
    print(ans[i])

Submission status: Time Limit Exceeded

Solution code:
N,M,Q = [int(x) for x in input().split()]

train = [0]*N*N

for i in range(M):
    l,r = [int(x)-1 for x in input().split()]
    for i in range(N):
        for j in range(i,N):
            if i <= l and r <= j:
                train[i*N+j]+=1

for i in range(Q):
    l,r = [int(x)-1 for x in input().split()]
    print(train[l*N+r])

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
n,m,q = map(int,raw_input().split())

imos = [[0 for i in xrange(n)] for j in xrange(n)]

for i in xrange(m):
	f,t = map(int,raw_input().split())
	f -= 1
	t -= 1
	for j in range(f+1):
		imos[j][t] += 1

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

for i in xrange(n):
	imos[i] = np.cumsum(imos[i])

for i in xrange(q):
	a,b = map(int,raw_input().split())
	print imos[a-1][b-1]

Submission status: Time Limit Exceeded

Solution code:
imos = [[0 for j in range(501)]for i in range(501)]
query = []
N,M,Q = map(int,input().split())
for i in range(M):
    L,R = map(int,input().split())
    imos[L][R] += 1
for i in range(Q):
    p,qq = map(int,input().split())
    query.append([p,qq])
for i in range(501):
    for j in range(1,501):
        imos[i][j] += imos[i][j-1]
for q in query:
    ans = 0
    for i in range(q[0],N+1):
        ans += imos[i][q[1]]
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
n, m, qqq = map(int, input().split())
LR = [[0 for _ in range(n)]for __ in range(n)]

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


for i in range(qqq):
    p, q = map(int, input().split())
    ans = 0
    print(LR[p-1][q-1])
# print(LR)

Submission status: Time Limit Exceeded

Solution code:
n, m, q = [int(_) for _ in input().split()]
lr = []
for i in range(0, m):
    li, ri = [int(_) for _ in input().split()]
    lr.append([li, ri])
lr = sorted(lr, key=lambda x:(x[0], x[1]))

pq = []
for i in range(0, q):
    pi, qi = [int(_) for _ in input().split()]
    pq.append([pi, qi])

for i in range(0, q):
    counti = 0
    flag = False
    for j in range(0, m):
        if j == m - 1:
            i_end = m
            break
        elif pq[i][0] >= lr[j][0] and not flag:
            flag = True
            i_start = j
        elif pq[i][0] < lr[j][0]:
            i_end = j+1
            break
    for j in range(i_start, m):
        if pq[i][0] <= lr[j][0] and pq[i][1] >= lr[j][1]:
            counti += 1
    print(counti)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
n, m, q = map(int, input().split())
m_list = []
for i in range(m):
    m_list.append(list(map(int, input().split())))
m_list = sorted(m_list)
q_list = []
for i in range(q):
    q_list.append(list(map(int, input().split())))
train_map = np.array([[0 for i in range(n)] for ii in range(n)])
for m_ in m_list:
    start, end = m_[0], m_[1]
    train_map[:start, end-1:] += 1
for q_ in q_list:
    q_s, q_e = q_[0]-1, q_[1]-1
    print(train_map[q_s, q_e])

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
import bisect
n,m,q = map(int,input().split())
lr = []
s = []
for i in range(m):
    l = list(map(int,input().split()))	
    lr.append(l)
    s.append(l[0])
lr.sort()
s.sort()

ass = np.zeros((n,n))
#print(ass)
#print(lr)

for i in range(n):
    k = bisect.bisect_left(s,i+1)
    
    for j in range(k,m):
        ass[i][lr[j][1]-1]+=1
        
#print(ass)

for i in range(q):
    p,qa = map(int,input().split())
    ans = sum(ass[p-1][:qa:])
    print(int(ans))

Submission status: Time Limit Exceeded

Solution code:
N,M,Q = map(int,input().split())
L = []
R = []
ANS = []
for i in range(M) :
    l,r = map(int,input().split())
    L.append(l)
    R.append(r)
for j in range(Q) :
    p,q = map(int,input().split())
    ans = 0
    for k in range(len(L)) :
        if p <= L[k] and R[k] <= q :
            ans += 1
    ANS.append(ans)
for z in range(len(ANS)) :
    print(ANS[z])

Submission status: Time Limit Exceeded

Solution code:
n, m, Q = [int(i) for i in input().split()]
l_list = []
r_list = []
p_list = []
q_list = []
for _ in range(m):
    l, r = [int(i) for i in input().split()]
    l_list.append(l)
    r_list.append(r)

for _ in range(Q):
    p, q = [int(i) for i in input().split()]
    p_list.append(p)
    q_list.append(q)


start_map = [[] for i in range(n)]
end_map = [[] for i in range(n)]

for i in range(m):
    l = l_list[i]
    r = r_list[i]

    start_map[l - 1].append(i)
    end_map[r - 1].append(i)

for i in range(Q):
    count = 0
    p = p_list[i]
    q = q_list[i]
    start_list = []
    end_list = []
    for j in range(p, q+1):
        start_list.extend(start_map[j-1])
        end_list.extend(end_map[j-1])
    rail_set = set(start_list) & set(end_list)

    print(len(rail_set))

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python
# coding: utf-8
#


def main(N, M, Q, l, r, p, q):
    for i in range(Q):
        retval = 0
        for j in range(M):
            if p[i] <= l[j] and r[j] <= q[i]:
                retval += 1
        print(retval)
                
if __name__ == '__main__':
    try:
        N, M, Q = list(map(int,input().strip().split(' ')))
        l = []
        r = []
        p = []
        q = []
        for i in range(M):
            a, b = list(map(int, input().strip().split(' ')))
            l.append(a)
            r.append(b)
        for i in range(Q):
            a, b = list(map(int, input().strip().split(' ')))
            p.append(a)
            q.append(b)
        main(N, M, Q, l, r, p, q)

            
    except EOFError:
        pass

Submission status: Time Limit Exceeded

Solution code:
n,m,q = list(map(lambda x : int(x),input().split()))


exps = list()

for i in range(m):
    exps.append(list(map(lambda x : int(x),input().split())))

terms = list()

for i in range(q):
    terms.append(list(map(lambda x : int(x),input().split())))


for term in terms:
    count = 0
    for exp in exps:
        if term[0] <= exp[0] and exp[1] <= term[1]:
            count +=1

    print(count)

Submission status: Time Limit Exceeded

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

res = [[0]*N for i in range(N)]

def lsadd(L,R):
    L-=1
    R-=1
    for i in range(0,L+1):
        for j in range(R,N):    
            res[i][j] += 1

for l,r in LR:
    lsadd(l,r)

for p,q in pq:
    print(res[p-1][q-1])

Submission status: Time Limit Exceeded

Solution code:
n,m,q = map(int,input().split())
i = [list(map(int, input().split())) for _ in range(m)]
j = [list(map(int, input().split())) for _ in range(q)]
for p in j:
  count = 0
  for l in i:
    if p[0] <= l[0] and l[1] <= p[1]:
      count += 1
  print(count)

Submission status: Time Limit Exceeded

Solution code:
from bisect import bisect_left

n, m, q = map(int, input().split())
LR = [0]*m
for i in range(m):
    LR[i] = list(map(int, input().split()))
P = [0]*q
Q = [0]*q
for i in range(q):
    P[i], Q[i] = map(int, input().split())

LR.sort(key=lambda x: x[0])
L = list(map(lambda x: x[0], LR))

for i in range(q):
    l = bisect_left(L, P[i])
    r = bisect_left(L, Q[i]+1)-1
    cnt = 0
    for j in range(l, r+1):
        if LR[j][1] <= Q[i]:
            cnt += 1
    print(cnt)

Submission status: Time Limit Exceeded

Solution code:
n, m, q = map(int, input().split())
ll = [[0, 0] for i in range(m)]
p = [[0, 0] for i in range(m)]
for i in range(m):
    ll[i][0], ll[i][1] = map(int, input().split())
for i in range(q):
    p[i][0], p[i][1] = map(int, input().split())
for i in range(q):
    ans = 0
    for j in range(m):
        if p[i][0] <= ll[j][0] and ll[j][1] <= p[i][1]:
            ans += 1
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
n, m, q_l = map(int, input().split() )
l = [0]*m
r = [0]*m
p = [0]*q_l
q = [0]*q_l

for i in range(m) :
   l[i] , r[i] = map(int, input().split() )
for i in range(q_l) :
   p[i] , q[i] = map(int, input().split() )

for i in range(q_l) :

   a = 0

   for j in range(m) :
      if (p[i]<=l[j]) and (r[j]<=q[i]) :
         a = a+1

   print(a)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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

res = np.zeros((N, N), dtype=int)

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

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

for q in query:
    print(res[q[0]-1, q[1]-1])

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N, M, Q = map(int, input().split())		# 5 7 2

A=[]
for i in range(M):
	l, r = map(int, input().split())		# 5 7
	A.append( (l,r) )

#print(A)

for i in range(Q):
	p, q = map(int, input().split())		# 5 7
	
	ans=0
	for a in A:
		if (p<=a[0])and(a[1]<=q): ans+=1
	else:
		print(ans)

Submission status: Time Limit Exceeded

Solution code:
n,m,q = map(int,raw_input().split())

imos = [[0 for i in range(n)] for j in range(n)]

for i in range(m):
	f,t = map(int,raw_input().split())
	f -= 1
	t -= 1
	for j in range(f+1):
		imos[j][t] += 1

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


for i in range(q):
	a,b = map(int,raw_input().split())
	print imos[a-1][b-1]

Submission status: Time Limit Exceeded

Solution code:
[n,m,q]=[int(i) for i in input().split()]
lr=[]
pq=[]
a=0
for i in range(m):
    lr.append(input().split())
for i in range(q):
    pq.append(input().split())
"""
高橋王国には, 東西にのびる 1 本の線路がある. これに沿って N 個の都市があり, 西から順に都市 1,2,3,[cdots],N と番号づけられている.
AtCoder Express という会社は M 本の列車を保有しており, 列車 i は都市 Li から都市 Ri の区間 (Li=Ri の場合もある) を走っている.

この王国の国王である高橋君は, Q 個のことに興味を持った. 具体的には, i=1,2,3,[dots],Q のときの以下の質問の答えを求めたくなった.

都市 pi から都市 qi までの区間に, 走る区間が 完全に含まれる 列車の本数. 言い換えれば, pi≤Lj と Rj≤qi が両方成り立つような列車 j の本数.
高橋君は天才である. しかし流石の彼でも, 膨大なデータを処理することはできない. 高橋君のために, Q 個の質問それぞれに対して答えを求めよ.
"""
#print(lr)
#print(pq)
for i in range(len(pq)):
    for j in range(len(lr)):
        if int(pq[i][0])<=int(lr[j][0]):
            if int(lr[j][1])<=int(pq[i][1]):
                a=a+1
                #print(lr[j])
    print(a)
    a=0

Submission status: Time Limit Exceeded

Solution code:
N, M, Q = map(int,input().split())
L_list = [0 for _ in range (M)]
R_list = [0 for _ in range (M)]
p_list = [0 for _ in range (Q)]
q_list = [0 for _ in range (Q)]

for m in range (M):
    L_list[m], R_list[m] = map(int,input().split())

for q in range (Q):
    p_list[q], q_list[q] = map(int,input().split())

for q in range (Q):
    ans = 0
    for m in range(M):
        if p_list[q] <= L_list[m] and R_list[m] <= q_list[q]:
            ans +=1
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
# S = input()
# K = int(input())
N, M, Q = map(int, input().split())
# A = list(map(int, input().split()))
LR = [list(map(int, input().split())) for _ in range(M)]
pq = [list(map(int, input().split())) for _ in range(Q)]

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

for left in range(N+1):
    for right in range(left, N+1):

        count = 0

        for i in range(M):
            if left <= LR[i][0] and right >= LR[i][1]:
                count += 1

        ar[left][right] = count

for j in range(Q):
    print(ar[pq[j][0]][pq[j][1]])

Submission status: Time Limit Exceeded

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

trains = []
for i in range(m):
  a, b = map(int, input().split())
  trains.append((a,b))

questions = []
for i in range(q):
  a, b = map(int, input().split())
  questions.append((a,b))

for question in questions:
  cnt = 0
  for train in trains:
    if train[0] < question[0]:
      continue
    if train[1] > question[1]:
      continue
    cnt += 1
    
  print(cnt)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
def run(n, m, qq, l, r, p, q):
    cnt = []
    for i in range(qq):
        tmp_cnt = 0
        for j in range(m):
            if p[i] <= l[j] and r[j] <= q[i]:
                tmp_cnt += 1
        cnt.append(tmp_cnt)
    return cnt


def read_line():
    n, m, qq = map(int, input().split())
    l = []
    r = []
    for i in range(m):
        tl, tr = map(int, input().split())
        l.append(tl)
        r.append(tr)
    p = []
    q = []
    for i in range(qq):
        tp, tq = map(int, input().split())
        p.append(tp)
        q.append(tq)
    return (n, m, qq, l, r, p, q)


def main():
    n, m, qq, l, r, p, q = read_line()
    ret = run(n, m, qq, l, r, p, q)
    for i in range(len(ret)):
        print(ret[i])


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
#encoding utf-8

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)

# def Answer(i):
#     count = 0
#     for j in range(M):
#         if p[i] <= L[j] and R[j] <= q[i]:
#             count += 1
#     return count

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: Time Limit Exceeded

Solution code:
N,M,Q=map(int,input().split())
#print(N,M,Q)
list1=[]

for i in range(M):
    ts,tg=map(int,input().split())
    list1.append([ts,tg])
#print(list1)
cnt=0
for j in range(Q):
    qs,qg=map(int,input().split())
    for k in range(M):
        if list1[k][0]>=qs and list1[k][1]<=qg:
            cnt+=1
    print(cnt)
    cnt=0

Submission status: Time Limit Exceeded

Solution code:
N, M, Q = map(int, input().strip().split())
train_starts = {}
for n in range(1, N + 1):
  train_starts[n] = []

for _ in range(M):
  L, R = map(int, input().strip().split())
  train_starts[L].append(R)

for _ in range(Q):
  p, q = map(int, input().strip().split())
  num_trains = 0
  for _p in range(p, N + 1):
    if _p not in train_starts or _p > q:
      continue
    else:
      num_trains += len([_q for _q in train_starts[_p] if _q <=q])
  print(num_trains)

Submission status: Time Limit Exceeded

Solution code:
# input
N, M, Q = map(int, input().split())
Trains = [list(map(int, input().split())) for _ in range(M)]
Trains = sorted(Trains)
Questions = {}
for i in range(Q):
    Questions[i] = list(map(int, input().split()))

Questions = sorted(Questions.items(), key = lambda x: x[1])

Ans = [0 for _ in range(Q)]
left = 0

for i in range(Q):
    num = Questions[i][0]
    p = Questions[i][1][0]
    q = Questions[i][1][1]
    for j in range(left, M):
        if p <= Trains[j][0]:
            left = j
            for k in range(j, M):
                if q >= Trains[k][1]:
                    Ans[num] += 1
            break

for i in range(Q):
    print(Ans[i])

Submission status: Time Limit Exceeded

Solution code:
[n,mc,qc]=[int(i) for i in input().split()]

m=[]
for i in range(mc):
    m.append([int(i) for i in input().split()])

q=[]
for i in range(qc):
    q.append([int(i) for i in input().split()])

for nowq in q:
    count=0
    for nowm in m:
        if nowq[0]<=nowm[0] and nowq[1]>=nowm[1]:
            count+=1
    print(count)

Submission status: Time Limit Exceeded

Solution code:
N,M,Q = (int(i) for i in input().split())

L = []
R = []
for i in range(M):
    Lin,Rin = (int(i) for i in input().split())
    L.append(Lin)
    R.append(Rin)

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


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

Submission status: Time Limit Exceeded

Solution code:
n, m, qqq = map(int, input().split())
LR = [[] for _ in range(n)]

for i in range(m):
    l, r = map(int, input().split())
    for j in range(l):
        LR[j].append(r)


for i in range(qqq):
    p, q = map(int, input().split())
    ans = 0
    for j in LR[p-1]:
        if j <= q:
            ans+=1
    print(ans)

Submission status: Time Limit Exceeded

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())
    for i in range(R,N+1):
        NN[L][i] += 1

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

Submission status: Time Limit Exceeded

Solution code:
N,M,Q = map(int,input().split())
Exp = [list(map(int,input().split())) for i in range(M)]
Query = [list(map(int,input().split())) for i in range(Q)]
for q in Query:
    ans = 0
    for e in Exp:
        if q[0] <= e[0] and e[1] <= q[1]:
            ans += 1
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
n, m, q = map(int,input().split())
l = []
p = []
for i in range(m):
    l.append(list(map(int, input().split())))    
for i in range(q):
    a = 0
    p = list(map(int, input().split()))
    for j in l:
        if j[0] >= p[0] and j[1] <= p[1]:
            a += 1
    print(a)

Submission status: Time Limit Exceeded

Solution code:
N, M, Q = map(int,input().split())
p=[0,]
q=[0,]
m =  [[0 for y in range(N+1)] for x in range(N+1)]

for i in range(M):
    l, r = map(int,input().split())
    for j in range(0, l+1):
        for k in range(r,N+1):
            m[j][k]+=1

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

for i in range(1,Q+1):
    print(m[p[i]][q[i]])

Submission status: Time Limit Exceeded

Solution code:
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()
alist.reverse()
for j in range(q):
    count=0
    p,q=map(int,input().split())
    for j in alist:
        if p<=j[0] and q>=j[1]:
            count+=1
        elif p>j[0]:
            break
    print(count)

Submission status: Time Limit Exceeded

Solution code:
def abc106_d():
    import numpy as np
    n, m, q = map(int, input().split())
    lrs = [0 for _ in range(m)]
    pqs = [0 for _ in range(q)]
    for i in range(m):
        lrs[i] = list(map(int, input().split()))
    for i in range(q):
        pqs[i] = list(map(int, input().split()))

    lrs = np.array(lrs)
    pqs = np.array(pqs)

    for pq in pqs:
        print(sum(np.all(lrs >= pq[0], axis=1)[np.all(lrs <= pq[1], axis=1)]))

    return 0


abc106_d()

Submission status: Time Limit Exceeded

Solution code:
#encoding utf-8

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)

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

for i in range(Q):
    print(Answer(i))

Submission status: Time Limit Exceeded

Solution code:
import sys
stdin = sys.stdin
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()

N, M, Q = na()
L=[]
R=[]
for i in range(M):
  L_tmp,R_tmp = na()
  L.append(L_tmp)
  R.append(R_tmp)

def trains(p,q):
  ans = 0
  for i in range(M):
    if p<=L[i]:
      if q>=R[i]:
        ans += 1
  return ans

for i in range(Q):
  p,q=na()
  print(trains(p,q))

Submission status: Time Limit Exceeded

Solution code:
N, M, Q = [int(i) for i in input().strip().split(" ")]
LR = []
for i in range(M):
    LR.append([int(i) for i in input().strip().split(" ")])

for i in range(Q):
    p, q = [int(i) for i in input().strip().split(" ")]
    count = 0
    for j in LR:
        if p <= j[0] and j[1] <= q:
            count += 1
    print(count)

Submission status: Time Limit Exceeded

Solution code:
import sys
e=sys.stdin.readlines()
N,M,Q=map(int,e[0].split())
dp=[[0]*-~N for _ in[0]*-~N]
for x in e[1:M+1]:
    L,R=map(int,x.split())
    for i in range(1,L+1):
        for j in range(R,N+1):
            dp[i][j] += 1
for x in e[M+1:]:
    p,q=map(int,x.split())
    print(dp[p][q])

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
n,m,Q = map(int,input().split())
l = np.zeros(m)
r = np.zeros(m)
p = np.zeros(Q)
q = np.zeros(Q)

for i in range(m):
    a,b = map(int,input().split())
    l[i] = a
    r[i] = b
for i in range(Q):
    a,b = map(int,input().split())
    p[i] = a
    q[i] = b


for i in range(Q):
    print(np.sum(r[np.where(l >= p[i])] <= q[i]))

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin
# stdin = open('sample.txt')


def main():
    N, M, Q = [int(x) for x in stdin.readline().rstrip().split()]
    LR = [[int(x) for x in stdin.readline().split()] for _ in range(M)]
    pq = [[int(x) for x in stdin.readline().split()] for _ in range(Q)]
    for p, q in pq:
        count = 0
        for L, R in LR:
            if p <= L and R <= q:
                count += 1
        print(count)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
s = input().split(" ")
N = int(s[0])
M = int(s[1])
Q = int(s[2])

ls = []
for i in range(M) : 
    s = input().split(" ")
    L = int(s[0])
    R = int(s[1])
    ls.append((L , R))

for j in range(Q) : 
    s = input().split(" ")
    p = int(s[0])
    q = int(s[1])
    
    count = 0
    for elem in ls : 
        if elem[0] >= p and elem[1] <= q : 
            count += 1
    print(count)

Submission status: Time Limit Exceeded

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

for i in range(q):
	count = 0
	for j in range(m):
		if a[j][0] >= b[i][0] and a[j][1] <= b[i][1]:
			count += 1
	print(count)

Submission status: Time Limit Exceeded

Solution code:
n, m, Q = map(int, input().split())

trainList = []
for _ in range(m):
    l, r = map(int, input().split())
    trainList.append([l, r])

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

def getOverNum(p, q):
    c = 0
    for i in range(m):
        l, r = trainList[i][0], trainList[i][1]
        if p <= l and r <= q:
            c += 1
    return c

for i in range(Q):
    print(getOverNum(*questList[i]))

Submission status: Time Limit Exceeded

Solution code:
li = list(map(int, input().split()))
N = li[0]
M = li[1]
Q = li[2]

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

q = []
for i in range(Q):
    q = list(map(int, input().split()))
    count=0
    for i in range(M):
        if q[0] <= a[i][0] and q[1] >= a[i][1]:
            count += 1
    print(count)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
n,m,q = map(int,input().split(" "))
train = np.array([list(map(int,input().split(" "))) for i in range(m)])
data = np.array([list(map(int,input().split(" "))) for i in range(q)])

for d in data:
    a = np.array([1 if t[0]>=d[0] and t[1]<=d[1] else 0 for t in train])
    print(np.sum(a))

Submission status: Time Limit Exceeded

Solution code:
import bisect

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

trains = [list(map(int, input().split())) for i in range(M)]
intervals = [list(map(int, input().split())) for i in range(Q)]
trains.sort(key = lambda x: x[1])
L = [train[0] for train in trains]
R = [train[1] for train in trains]
for i in range(Q):
    pi, qi = intervals[i]
    right = bisect.bisect_right(R, qi)
    A = sorted(L[:right])
    left = bisect.bisect_left(A, pi)
    print(right - left)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
n,m,Q = map(int,input().split())
l = np.zeros(m)
r = np.zeros(m)
p = np.zeros(Q)
q = np.zeros(Q)

for i in range(m):
    a,b = map(int,input().split())
    l[i] = a
    r[i] = b
for i in range(Q):
    a,b = map(int,input().split())
    p[i] = a
    q[i] = b


for i in range(Q):
    print(np.sum((l >= p[i])*(r <= q[i])))

Submission status: Time Limit Exceeded

Solution code:
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 j in range(q):
    count=0
    p,q=map(int,input().split())
    for j in alist:
        if p<=j[0] and q>=j[1]:
            count+=1
    print(count)

Submission status: Time Limit Exceeded

Solution code:
N,M,Q=map(int,input().split())
LR=[]
for _ in range(M):
    lr=list(map(int,input().split()))
    LR.append(lr)
    
for _ in range(Q):
    p,q=map(int,input().split())
    ans=0
    for lr in LR:
        if p<=lr[0]: ans+=int(q>=lr[1])
    print(ans)

Submission status: Time Limit Exceeded

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

train=[]
Query=[]
for i in range(M):
  train.append(list(map(int,input().split())))
for i in range(Q):
  answer=0
  Query=list(map(int,input().split()))
  for j in range(M):
    if train[j][0]>=Query[0] and train[j][1]<=Query[1]:
      answer+=1
  print(answer)

Submission status: Time Limit Exceeded

Solution code:
n, m, q = map(int, input().split())
m_list = []
for i in range(m):
    m_list.append(list(map(int, input().split())))
m_list = sorted(m_list)
q_list = []
for i in range(q):
    q_list.append(list(map(int, input().split())))
for q_ in q_list:
    cnt = 0
    q_s, q_e = q_[0], q_[1]
    for m_ in m_list:
        if q_s <= m_[0] <= q_e and q_s <= m_[1] <= q_e:
            cnt += 1
        elif q_e < m_[0]:
            break
    print(cnt)

Submission status: Time Limit Exceeded

Solution code:
# input
N, M, Q = map(int, input().split())
Trains = [list(map(int, input().split())) for _ in range(M)]
Trains = sorted(Trains)

for i in range(Q):
    p, q = map(int, input().split())
    ans = 0
    for j in range(M):
        if p <= Trains[j][0]:
            for k in range(j, M):
                if q >= Trains[k][1]:
                    ans += 1
            break
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
N,M,Q = [int(x) for x in input().split()]

train = [0]*M

for i in range(M):
    train[i] = [int(x) for x in input().split()]

question = [0]*Q

for i in range(Q):
    question[i]  = [int(x) for x in input().split()]


ans = [0]*Q
for i in train:
    for j in range(Q):
        if question[j][0] <= i[0] and i[1] <= question[j][1]:
            ans[j]+=1

for i in ans:
    print(i)

Submission status: Time Limit Exceeded

Solution code:
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
for _ in[0]*Q:
    p,q=map(int,input().split())
    print(dp[p][q])

Submission status: Accepted

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

x = [[0 for i in range(n)] for j in range(n)]

for i in range(m):
    a, b = map(int, input().split())
    x[a-1][b-1] += 1

for j in range(1, n):
    for k in range(n-j):
        x[k][j+k] += x[k][j+k-1] + x[k+1][j+k] - x[k+1][j+k-1]

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