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 -*-
from operator import itemgetter

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

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


LRi.sort(key=itemgetter(1))

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

# pqi.sort(key=itemgetter(1))

#
# print(LRi)
# print(pqi)

for (p, q) in pqi:
    cnt = 0
    for (L,R) in LRi:
        if p <= L and R <= q:
            cnt += 1
        elif q < R:
            break
    print(cnt)

Submission status: Time Limit Exceeded

Solution code:
n, m, k = list(map(int, input().split()))
lr = [list(map(int, input().split())) for _ in range(m)]
pq = [list(map(int, input().split())) for _ in range(k)]

l = [lr[_][0] for _ in range(m)]
r = [lr[_][1] for _ in range(m)]
p = [pq[_][0] for _ in range(k)]
q = [pq[_][1] for _ in range(k)]

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

Submission status: Time Limit Exceeded

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

ans = []
for i in range(len(p)):
    cnt = 0
    for j in range(len(L)):
        if (p[i] <= L[j] and q[i] >= R[j]):
            cnt += 1
    ans.append(cnt)

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

Submission status: Time Limit Exceeded

Solution code:
from bisect import bisect_left
import numpy as np
n,m,q=map(int,input().split())
s=[]
t=[]
ss=[]
for i in range(m):
    x,y=map(int,input().split())
    ss.append((x,y))
ss.sort()
for x,y in ss:
    s+=[x]
    t+=[y]
for i in range(q):
    x,y=map(int,input().split())
    bi=bisect_left(s,x)
    u=np.array(t[bi:])
    print(len(u[u<=y]))

Submission status: Time Limit Exceeded

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

from collections import defaultdict


def solve():
    n, m, q = map(int, input().split())
    d = defaultdict(list)
    for i in range(m):
        l, r = map(int, input().split())
        d[l].append(r)
    table = [[0 for i in range(n + 1)]for j in range(n + 1)]
    for i in range(1, n + 1):
        dk = [p for p in d.keys() if i <= p]
        for j in range(1, n + 1):
            tans = 0
            for k in [p for p in dk if p <= j]:
                tans += len([q for q in d[k] if q <= j])
            table[i][j] = tans
    for i in range(q):
        l, r = map(int, input().split())
        print(table[l][r])


if __name__ == "__main__":
    solve()

Submission status: Time Limit Exceeded

Solution code:
n, m, qn = map(int, input().split())
t = [list(map(int, input().split())) for _ in range(m)]
qs = [list(map(int, input().split())) for _ in range(qn)]

r = dict()
for i in range(1, n + 1):
    r[i] = set()
    
l = dict()
for i in range(1, n + 1):
    l[i] = set()

for x in range(len(t)):
    L, R = t[x]
    for i in range(R, n + 1):
        l[i].add(x)
    for i in range(1, L + 1):
        r[i].add(x)

for p, q in qs:
    print(len(r[p] & l[q]))

Submission status: Time Limit Exceeded

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

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

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

def ans(l,r,p,q):
    if p<=l and r<=q:
        return 1
    else:
        return 0


for i in range(Q):
    answer=0
    for j in range(m):
        answer+=int(ans(l[j],r[j],p[i],q[i])) 
    print(answer)

Submission status: Time Limit Exceeded

Solution code:
n, m, q = [int(i) for i in input().split()]
m_list = [[0 for i in range(n+1)] for j in range(n+1)]
dynamic = [[0 for i in range(n+1)] for j in range(n+1)]

for i in range(m):
    l, r = [int(i) for i in input().split()]
    m_list[l][r] += 1

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

for i in range(q):
    l, r = [int(i) for i in input().split()]
    print(dynamic[l][r])

Submission status: Time Limit Exceeded

Solution code:
n,m,q=map(int,input().split())
lr=[list(map(int,input().split())) for i in range(0,m)]
pq=[list(map(int,input().split())) for i in range(0,q)]

for x in pq:
    print(sum([1 for i in lr if(x[0]<=i[0] and x[1]>=i[1])]))

Submission status: Time Limit Exceeded

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

t_list = []
q_list = []

for i in range(m):
  l, r = map(int, input().split())
  t_list.append((l, r))

for i in range(m, m + q):
  p, q = map(int, input().split())
  q_list.append((p, q))

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

Submission status: Time Limit Exceeded

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

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

p = []
q = []
for i in range(Q):
    line = input().split()
    p.append(int(line[0]))
    q.append(int(line[1]))

for pp, qq in zip(p, q):
    count = 0
    for LL, RR in zip(L, R):
        if pp <= LL and RR <= qq:
            count += 1
    print(count)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N, M, Q = list(map(int, input().split()))
LR = {k:np.array([]) for k in range(1, N+1)}
for i in range(M):
    l, r = list(map(int, input().split()))
    LR[l] = np.append(LR[l], r)

for i in range(Q):
    re = 0
    p, q = list(map(int, input().split()))
#    print(i, p, q)
    for j in range(p,q + 1):
        re += np.sum(LR[j] <= q)
    print(re)

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())
    LR[l-1][r-1]+=1


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

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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

L = [None] * M
R = [None] * M
p = [None] * Q
q = [None] * Q

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

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

A = np.zeros((N, N))

for i in range(M):
    A[:L[i]:, R[i]-1:] += 1

for i in range(Q):
    print(int(A[p[i]-1, q[i]-1]))

Submission status: Time Limit Exceeded

Solution code:
NMQ = list(map(int,input().split()))
N=NMQ[0]
M=NMQ[1]
Q=NMQ[2]
reg=[]
for i in range(M):
	r=list(map(int,input().split()))
	reg.append(r)
que=[]
for i in range(Q):
	q=list(map(int,input().split()))
	que.append(q)
for i in range(Q):
	count=0
	pi=que[i][0]
	qi=que[i][1]
	for j in range(M):
		Lj=reg[j][0]
		Rj=reg[j][1]
		if pi<=Lj and Rj<=qi:
			count=count+1
		else:
			pass
	print(count)

Submission status: Time Limit Exceeded

Solution code:
data = input()

nmq = data.split()

R = []
L = []
for lop in range(int(nmq[1])):
    lr = input()
    buf = lr.split()
    
    L.append(buf[0])
    R.append(buf[1])
    
for lop in range(int(nmq[2])):
    cnt = 0
    q = input()
    Q = q.split()
    for lop2 in range(int(nmq[1])):
        if  (int(L[lop2]) >= int(Q[0])) and (int(R[lop2]) <= int(Q[1])):
            cnt = cnt + 1
    print(cnt)

Submission status: Time Limit Exceeded

Solution code:
n,m,q = map(int, input().split())
lr = [tuple(map(int, input().split())) for _ in range(m)]
pq = [tuple(map(int, input().split())) for _ in range(q)]

x = [[] for _ in range(n)]
for l,r in lr:
    x[l-1].append(r-1)
for p,q in pq:
    ans=0
    for i in range(p-1,q):
        for j in x[i]:
            if j<q:
                ans+=1
    print(ans)
exit(0)

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)]
queries = [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]

dp = [[0] * N for i in range(N)]
for i in range(N):
    for j in range(i, N):
        right = bisect.bisect_right(R, j + 1)
        A = sorted(L[:right])
        left = bisect.bisect_left(A, i + 1)
        dp[i][j] = right - left

for q in range(Q):
    pi, qi = queries[q]
    print(dp[pi - 1][qi - 1])

Submission status: Time Limit Exceeded

Solution code:
# coding=utf-8

if __name__ == '__main__':
    N, M, Q = map(int, input().split())

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

    for j in range(Q):
        counter = 0
        question = list(map(int, input().split()))
        for train in train_list:
            if question[0] <= train[0] and question[1] >= train[1]:
                counter += 1
        print(counter)

Submission status: Time Limit Exceeded

Solution code:
n,m,q = input().split()
llist = []
rlist = []
plist = []
qlist = []
for i in range(int(m)):
    l,r = input().split()
    llist.append(int(l))
    rlist.append(int(r))
for i in range(int(q)):
    p,q = input().split()
    count = 0
    for j in range(len(llist)):
        if int(p) <= llist[j] and int(q) >= rlist[j]:
            count += 1
    print(count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import sys
import collections
import numpy as np
e=sys.stdin.readlines()
N,M,Q=map(int,e[0].split())
dp=np.zeros([N+1,N+1])
for k,c in collections.Counter(e[1:M+1]).items():
    L,R=map(int,k.split())
    dp[1:L+1,R:N+1] += c
ans=''
for x in e[M+1:]:
    p,q=map(int,x.split())
    ans+=str(int(dp[p][q]))+'\n'
print(ans[:-1])

Submission status: Time Limit Exceeded

Solution code:
n,m,q = map(int,input().split())
train = []
num = [[0,0] for i in range(n)]
for i in range(m):
  l,r = map(int,input().split())
  train.append([l,r])
  num[l-1][0] += 1

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

p = []
for i in range(m):
  p.append(train[i][0])

c = 0
for i in range(n):
  num[i][1] = c
  c += p.count(i+1)

for i in range(q):
  l,r = map(int,input().split())
  ans = 0
  for j in range(l,r+1):
    s = num[j-1][0]
    t = num[j-1][1]
    u = 0
    if(train[t+s-1][1] < r):
      ans += s
    else:
      for k in range(s):
        if(train[t+k][1] > r):
          u = s - k
          break
      ans += s - u
  print(ans)

Submission status: Time Limit Exceeded

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

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)]
queries = [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]

dp = [[0] * N for i in range(N)]
for i in range(N):
    for j in range(i, N):
        right = bisect.bisect_right(R, j + 1)
        A = sorted(L[:right])
        left = bisect.bisect_left(A, i + 1)
        dp[i][j] = right - left
for q in range(Q):
    pi, qi = queries[q]
    print(dp[pi - 1][qi - 1])

Submission status: Time Limit Exceeded

Solution code:
N,M,Q = map(int, input().split())
L = [0]*M
R = [0]*M
p = [0]*Q
q = [0]*Q

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

for i in range(Q):
  p[i],q[i] = map(int, input().split())
  
for i in range(Q):
  count = 0
  for tr in range(M):
    if(p[i]<=L[tr]):
      if(R[tr]<=q[i]):  count += 1
  print(count)

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
# AtCoder Express 2

# 1,2,3,...,n 都市
# m 本の列車
# q この疑問
n, m, Q = list(map(lambda e:int(e), input().strip().split(' ')))
sections = []
for i in range(m):
    l, r = list(map(lambda e:int(e), input().strip().split(' ')))
    sections.append((l,r))
questions = []
for i in range(Q):
    l, r = list(map(lambda e:int(e), input().strip().split(' ')))
    questions.append((l,r))

for q in questions:
    ql, qr = q
    num = 0
    for secs in sections:
        l, r = secs
        if ql <= l and r <= qr:
            num += 1
    print(num)

Submission status: Time Limit Exceeded

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

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

for i in range(M):
    b,c = map(int,input().split())
    for j in range(b):
        for k in range(c-1,N):
            a[j][k] += 1


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

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N, M, Q = map(int, input().split())
LR = np.array([tuple(map(int, input().split())) for i in range(M)])
pq = np.array([tuple(map(int, input().split())) for i in range(Q)])

ans = []

for i in range(pq.shape[0]):
    tmp_len = LR.shape[0]
    ori = pq[i,0] <= LR[:,0]
    des = pq[i,1] >= LR[:,1]
    ans.append(str(sum(ori * des)))

print("\n".join(ans))

Submission status: Time Limit Exceeded

Solution code:
n,m,q = input().split()
llist = []
rlist = []
plist = []
qlist = []
for i in range(int(m)):
    l,r = input().split()
    llist.append(int(l))
    rlist.append(int(r))
for j in range(int(q)):
    p,q = input().split()
    plist.append(int(p))
    qlist.append(int(q))
for i in range(len(plist)):
    count = 0
    for j in range(len(llist)):
        if plist[i] <= llist[j] and qlist[i] >= rlist[j]:
            count += 1
    print(count)

Submission status: Time Limit Exceeded

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


def get_start(p, tmp):
    for L, i in tmp:
        if L <= p:
            return i
    return 0


def get_end(q, tmp):
    for L, i in tmp:
        if q < L:
            return i
    return 0


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)]
    LR = sorted(LR)

    tmp = []
    back = 0
    for i, (L, R) in enumerate(LR):
        if L == back:
            continue
        tmp.append((L, i))
        back = L

    pq = [[int(x) for x in stdin.readline().split()] for _ in range(Q)]
    for p, q in pq:
        count = 0

        start = get_start(p, tmp)
        # end = get_end(q, tmp)
        for L, R in LR[start:]:
            if p <= L and R <= q:
                count += 1
        print(count)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin
N, M, Q = [int(x) for x in stdin.readline().rstrip().split()]

LR = []
for i in range(M):
    tmp = stdin.readline().rstrip().split()
    LR.append(tmp)
pq = []
for i in range(Q):
    tmp = stdin.readline().rstrip().split()
    pq.append(tmp)

for i in range(len(pq)):
    count = 0
    p = int(pq[i][0])
    q = int(pq[i][1])
    for j in range(len(LR)):
        L = int(LR[j][0])
        if p <= L:
            R = int(LR[j][1])
            if R <= q:
                count += 1
    print(count)

Submission status: Time Limit Exceeded

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

L = []
R = []
LENGTH_LR = []
P = []
Q = []
LENGTH_PQ = []

for i in range(M):
  LL, RR = map(int,input().split())
  L.append(LL)
  R.append(RR)
  LENGTH_LR.append(LL-RR)
  
for i in range(T):
  PP, QQ = map(int,input().split())
  P.append(PP)
  Q.append(QQ)
  LENGTH_PQ.append(PP-QQ)
  
answer = []
for i in range(T):
  cc = 0
  for j in range(M):
    if (L[j] >= P[i]) and (R[j] <= Q[i]):
      cc += 1
  answer.append(cc)

for i in answer:
  print(i)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

for i in range(m):
    l, r = map(int, input().split())
    if l < n-r:
        for j in range(l):
            LR1[j].append(r)
    else:
        for j in range(r-1, n):
            LR2[j].append(l)


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

Submission status: Time Limit Exceeded

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

table = [[0 for _i in range(N+1)] for _j in range(N+1)]
for line in LR:
    table[line[0]][line[1]] += 1
for question in pq:
    p = question[0]
    q = question[1]
    ans = 0
    for i in range(p, q+1):
        ans += sum(table[i][p:q+1])
    print(ans)

Submission status: Time Limit Exceeded

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

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

p=[]
q=[]
for k in range(Q):
    p_tmp, q_tmp = list(map(int, input().split()))
    p.append(p_tmp)
    q.append(q_tmp)
    

for qi in range(Q):
    out = 0
    for i in range(m):
        if(l[i]>=p[qi] and r[i]<=q[qi]):
            out += 1
    print(out)

Submission status: Time Limit Exceeded

Solution code:
N,M,Q=map(int,input().split(" "))
train=[]
for i in range(M):
    train.append(input())
for j in range(Q):
    count=0
    a,b=map(int,input().split(" "))
    for k in range(M):
        c,d=map(int,train[k].split(" "))
        if a<=c and b>=d:
            count+=1
        else:
            pass
    else:
        print(count)

Submission status: Time Limit Exceeded

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

T = [] 
Q = []

for i in range(m):
    T.append(list(map(int,input().split())))
for i in range(q):
    Q.append(list(map(int,input().split())))

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

for t in T:
    for i in range(t[0]):
        for j in range(t[1]-1,n):
            ans[i][j] +=1

for qu in Q:
    print(ans[qu[0]-1][qu[1]-1])

Submission status: Time Limit Exceeded

Solution code:
n, m, q = (int(i) for i in input().split())
lr = [[int(i) for i in input().split()] for j in range(m)]
pq = [[int(i) for i in input().split()] for j in range(q)]

for a in pq:
    count = 0
    for b in lr:
        if a[0] <= b[0] and a[1] >= b[1]:
            count += 1
    print(count)

Submission status: Time Limit Exceeded

Solution code:
# your code goes here
buf = input().split()
N = int(buf[0])
M = int(buf[1])
Q = int(buf[2])
import numpy as np
train = np.zeros((N+1, N+1))
for i in range(M):
	buf = input().split()
	L = int(buf[0])
	R = int(buf[1])
	train[L][R] += 1
#print(train)
for i in range(Q):
	buf = input().split()
	p = int(buf[0])
	q = int(buf[1])
	buf_train = train[p:q+1, p:q+1]
	print(int(np.sum(buf_train)))

Submission status: Time Limit Exceeded

Solution code:
n,m,q = map(int,input().split())
train = []
num = [[0,0] for i in range(n)]
for i in range(m):
  l,r = map(int,input().split())
  train.append([l,r])
  num[l-1][0] += 1

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

p = []
for i in range(m):
  p.append(train[i][0])

c = 0
for i in range(n):
  num[i][1] = c
  c += p.count(i+1)

for i in range(q):
  l,r = map(int,input().split())
  ans = 0
  for j in range(l,r+1):
    s = num[j-1][0]
    t = num[j-1][1]
    u = 0
    for k in range(s):
      if(train[t+k][1] > r):
        u = s - k
        break
    ans += s - u
  print(ans)

Submission status: Time Limit Exceeded

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

from collections import defaultdict


def solve():
    n, m, q = map(int, input().split())
    d = defaultdict(list)
    for i in range(m):
        l, r = map(int, input().split())
        d[l].append(r)
    for i in range(q):
        l, r = map(int, input().split())
        ans = 0
        for k in [q for q in d.keys() if l <= q <= r]:
            ans += len([q for q in d[k] if q <= r])
        print(ans)


if __name__ == "__main__":
    solve()

Submission status: Time Limit Exceeded

Solution code:
def addDict(dic , elem) : 
    if elem in dic : 
        dic[elem] += 1
    else :
        dic[elem] = 1
    return dic

def zeroDict(dic , elem) : 
    if elem in dic : 
        dic[elem] += 0
    else :
        dic[elem] = 0
    return dic

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

ls = []
dic = {}
for i in range(M) : 
    s = input().split(" ")
    L = int(s[0])
    R = int(s[1])
    
    for j in range(1, N+1) : 
        for k in range(1, N+1) : 
            if L >= j and R <= k : 
                dic = addDict(dic , str(j)+ "-" + str(k))
            else : 
                dic = zeroDict(dic , str(j)+ "-" + str(k))
                


for j in range(Q) : 
    s = input().split(" ")
    p = int(s[0])
    q = int(s[1])
    
    print(dic[str(p) + "-" + str(q)])

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

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
n, m, q = [int(item) for item in input().split(" ")]
end = np.zeros((m,2),dtype=int)
query = np.zeros((q,2),dtype=int)
for i in range(m):
    end[i] = [int(item) for item in input().split(" ")]
for i in range(q):
    query[i] = [int(item) for item in input().split(" ")]
a = np.zeros((n,n), dtype=int)
np.add.at(a, [end[:,0]-1,end[:,1]-1], 1)
for item in query:
    print(np.sum(a[(item[0]-1):, :item[1]]))

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):
    p.append(list(map(int,input().split())))

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


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


for i in p:
    print(a[i[0]-1][i[1]-1])

Submission status: Time Limit Exceeded

Solution code:
N, M, Q = map(int,input().split())
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(1,Q+1):
    l, r = map(int,input().split())
    print(m[l][r])

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n, m, q = map(int, input().split())
lr = [tuple(map(int, input().split())) for _ in range(m)]
pq = [tuple(map(int, input().split())) for _ in range(q)]

for i in range(q):
    p, q = pq[i]
    c = 0
    for j in range(m):
        l, r = lr[j]
        if p <= l and r <= q:
            c += 1
    print(c)

Submission status: Time Limit Exceeded

Solution code:
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):
    pp,qq = map(int,input().split())
    p.append(pp)
    q.append(qq)

cnt = 0
for i in range(Q):
    x = p[i]
    y = q[i]
    for j in range(M):
        l = L[j]
        r = R[j]
        if x <= l and y >= r:
            cnt += 1
    print(cnt)
    cnt = 0

Submission status: Time Limit Exceeded

Solution code:
n, m, q = map(int, input().split())
tr = []
for i in range(m):
    l, r = map(int, input().split())
    tr.append((l, r))

qu = []
for i in range(q):
    p, q = map(int, input().split())
    qu.append((p, q))
    print(len(list(filter(lambda s: p <= s[0] and s[1] <= q, tr))))

Submission status: Time Limit Exceeded

Solution code:
#TLEなりそう

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

Train = []
Quiz = []
for j in range(M):
    l,r = map(int,input().split())
    Train.append([l,r])
    
for k in range(Q):
    p,q = map(int,input().split())
    Quiz.append([p,q])

for I in Quiz:
    ans = 0
    for J in Train:
        if I[0]<=J[0] and J[1]<=I[1]:
            ans += 1
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
def abc106_d():
    import numpy as np
    n, m, q = map(int, input().split())
    ls = np.zeros(m, dtype=int)
    rs = np.zeros(m, dtype=int)
    ps = np.zeros(q, dtype=int)
    qs = np.zeros(q, dtype=int)
    for i in range(m):
        ls[i], rs[i] = map(int, input().split())
    for i in range(q):
        ps[i], qs[i] = map(int, input().split())

    for i in range(q):
        print(sum((ls >= ps[i])[rs <= qs[i]]))

    return 0


abc106_d()

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N, M, Q = map(int, input().split())
LR = np.array([tuple(map(int, input().split())) for i in range(M)])
pq = np.array([tuple(map(int, input().split())) for i in range(Q)])


for i in range(pq.shape[0]):
    tmp_len = LR.shape[0]
    tmp_p = np.full(tmp_len, pq[i,0])
    tmp_q = np.full(tmp_len, pq[i,1])
    ori = tmp_p <= LR[:,0]
    des = tmp_q >= LR[:,1]
    print(sum(ori * des))

Submission status: Time Limit Exceeded

Solution code:
N, M, Q = map(int, input().split())
trains = []
questions = []
def make_range(L, R):
    return (pow(2, (R-L+1))-1)<<L-1

for i in range(M):
    a, b = map(int, input().split())
    trains.append(make_range(a, b))
    
for i in range(Q):
    a, b = map(int, input().split())
    questions.append(make_range(a, b))

    
for question in questions:
    res = 0
    for train in trains:
        if question | train == question:
            res += 1
    print(res)

Submission status: Time Limit Exceeded

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

A=[]
for i in range(m):
    b,c=map(int,input().split())
    A.append([b,c])
B=[]
for i in range(q):
    b,c=map(int,input().split())
    B.append([b,c,i])

C=[[0 for i in range(n+3)] for j in range(n+3)]
#print(C)
for i in range(m):
    C[A[i][0]][A[i][1]]+=1


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

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

D=[]

co=0
ml=0
mr=0
for i in range(q):
    l=B[i][0]
    r=B[i][1]
    nu=B[i][2]
    if ml<l :
        co=0
        for j in range(l,r+1):
            for k in range(j,r+1):
                co+=C[j][k]
        D.append([co,nu])
    else:
        for j in range(mr+1,r+1):
            for k in range(l,r+1):
                co+=C[k][j]
        D.append([co,nu])
    ml=l
    mr=r

D.sort(key=lambda x:x[1])
for i in range(q):
    print(D[i][0])

Submission status: Time Limit Exceeded

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


Query=[]
answer=[[0]*N for i in range(N)]
for i in range(M):
  L,R=map(int,input().split())
  for j in range(1,L+1):
    for k in range(R,N+1):
      answer[j-1][k-1]+=1

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
N, M, Q = [int(i) for i in input().strip().split(" ")]
train = [[0 for j in range(N)] for i in range(N)]
for i in range(M):
    l, r = [int(i)-1 for i in input().strip().split(" ")]
    for j in range(l+1):
        for k in range(N-1, r-1, -1):
            train[j][k] += 1

for i in range(Q):
    p, q = [int(i)-1 for i in input().strip().split(" ")]
    print(train[p][q])

Submission status: Time Limit Exceeded

Solution code:
#D
N,M,Q=map(int,input().split())
L,R,p,q=[0]*M,[0]*M,[0]*Q,[0]*Q
for i in range(M):
    L[i],R[i]=map(int,input().split())
for i in range(Q):
    p[i],q[i]=map(int,input().split())
#Q CHECK
for i in range(Q):
    s=0
    for j in range(M):
        if p[i]<=L[j] and R[j]<=q[i]:
            s+=1
    print(s)