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:
n,m,Q=[int(x) for x in input().split()]
l,r,p,q=[],[],[],[]
for _ in [1]*m:
    li,ri=[int(x) for x in input().split()]
    l.append(li)
    r.append(ri)
for _ in [1]*Q:
    pi,qi=[int(x) for x in input().split()]
    p.append(pi)
    q.append(qi)

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

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N, M, Q = list(map(int, input().split()))
p_q = np.zeros([Q, 2], dtype = int)
MAP = np.zeros([500, 500], dtype = int)

for _ in range(M):
    L, R = list(map(int, input().split()))
    MAP[L - 1][R - 1] += 1
for i in range(Q):
    p, q = list(map(int, input().split()))
    p_q[i][0] = p
    p_q[i][1] = q

for i in p_q:
    print(np.sum(MAP[i[0] - 1:i[1], i[0] - 1:i[1]]))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N, M, Q = list(map(int, input().split()))
p_q = []
MAP = np.zeros([500, 500], dtype = int)

for _ in range(M):
    L, R = list(map(int, input().split()))
    MAP[L - 1][R - 1] += 1
for _ in range(Q):
    p, q = list(map(int, input().split()))
    p_q.append((p, q))

for i in p_q:
    print(np.sum(MAP[i[0] - 1:i[1], i[0] - 1:i[1]]))

Submission status: Time Limit Exceeded

Solution code:
N, M, Q = list(map(int, input().split()))
L_R = []
p_q = []

for _ in range(M):
    L, R = list(map(int, input().split()))
    L_R.append((L, R))
for _ in range(Q):
    p, q = list(map(int, input().split()))
    p_q.append((p, q))

for i in p_q:
    count = 0
    for j in L_R:
        if(i[0] <= j[0] and j[1] <= i[1]):
            count += 1
    print(count)

Submission status: Time Limit Exceeded

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+1,e]+=1
b=a.cumsum(1)
for i in range(q):
  s,e=map(int,input().split())
  print(int(b[s,e]))

Submission status: Time Limit Exceeded

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+1,e:]+=1
for i in range(q):
  s,e=map(int,input().split())
  print(int(a[s,e]))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N, M, Q = map(int, input().split())
LR = []
for i in range(M):
    l, r = map(int, input().split())
    LR.append([l, r])
PQ = []
for i in range(Q):
    p, q = map(int, input().split())
    PQ.append([p, q])

ar = np.zeros([N, N])
for i in range(M):
    l, r = LR[i][0], LR[i][1]
    ar[l - 1][r - 1] += 1
for i in range(Q):
    p, q = PQ[i][0]-1, PQ[i][1]
    print(int(ar[p:q, p:q].sum()))

Submission status: Time Limit Exceeded

Solution code:
def main():
    """
    """
    N, M, Q = map(int, input().split())
    L, R = zip(*(
        map(int, input().split())
        for _ in range(M)
    ))
    p, q = zip(*(
        map(int, input().split())
        for _ in range(Q)
    ))

    # answers = f(N, M, Q, L, R, p, q)
    # experiment(N, M, Q, L, R, p, q)
    # answers = TLE(N, M, Q, L, R, p, q)
    answers = editorial(N, M, Q, L, R, p, q)
    for ans in answers:
        print(ans)


def editorial(N, M, Q, L, R, p, q):
    """
    ２次元累積和のライブラリを持っておくとよいらしい
        確かに実装ミスりそう

    """
    # LRの組合せ, N<=500より間に合う
    t1 = [[0] * (N+1) for _ in range(N+1)]
    t2 = [[0] * (N+1) for _ in range(N+1)]
    for l, r in zip(L, R):
        t1[l][r] += 1

    # Lごとの累積和
    for l in range(1, N+1):
        for r in range(1, N+1):
            t2[l][r] = t2[l][r-1] + t1[l][r]

    answers = []
    for _p, _q in zip(p, q):
        ans = 0
        for l in range(_p, _q+1):
            ans += t2[l][_q] - t2[l][_p-1]

        answers.append(ans)

    return answers


def TLE(N, M, Q, L, R, p, q):
    """
    10^5 * 10^5
    """
    answers = []
    for _p, _q in zip(p, q):
        ans = 0
        for left, right in zip(L, R):
            if _p <= left and right <= _q:
                ans += 1

        answers.append(ans)

    return answers


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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

L = np.zeros(M)
R = np.zeros(M)
X = np.zeros((501,501))
C = np.zeros((501,501))
p = 0
q = 0

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

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

Submission status: Time Limit Exceeded

Solution code:
def abc106_dx():
    import numpy as np
    import sys
    input = sys.stdin.readline

    n, m, q = map(int, input().split())
    ls = np.empty(m, dtype=int)
    rs = np.empty(m, dtype=int)
    ps = np.empty((q, 1), dtype=int)
    qs = np.empty((q, 1), 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(np.sum((ls >= ps[i])[rs <= qs[i]]))
    # for count in np.sum((ls >= ps) * (rs <= qs), axis=1):
    #     print(count)
    return 0


abc106_dx()

Submission status: Time Limit Exceeded

Solution code:
def abc106_dx():
    import numpy as np
    import sys
    input = sys.stdin.readline

    n, m, q = map(int, input().split())
    ls = np.zeros(m, dtype=int)
    rs = np.zeros(m, dtype=int)
    ps = np.zeros((q, 1), dtype=int)
    qs = np.zeros((q, 1), 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]]))
    # for count in np.sum((ls >= ps) * (rs <= qs), axis=1):
    #     print(count)
    return 0


abc106_dx()

Submission status: Time Limit Exceeded

Solution code:
a = input().split()
n = int(a[0])
m = int(a[1])
q = int(a[2])

table = [[] for i in range(n)]
for i in range(m):
	a = input().split()
	l = int(a[0]) - 1
	r = int(a[1]) - 1
	table[l].append(r)

		
for i in range(q):
	output = 0
	a = input().split()
	l = int(a[0]) - 1
	r = int(a[1]) - 1
	for k in range(l, r + 1):
		for j in table[k]:
			if r >= j:
				output += 1
	print (output)

Submission status: Time Limit Exceeded

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

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

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

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

cnt = 0
for i in range(q):
    for j in range(pi[i], qi[i]+1):
        for k in range(pi[i], qi[i]+1):
            cnt += tr[j][k]
    print(cnt)
    cnt = 0

Submission status: Time Limit Exceeded

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

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

pi = []
qi = []
for i in range(q):
    pq = list(map(int, input().split()))
    pi.append(pq[0])
    qi.append(pq[1])
#input finished

cnt = 0

for i in range(q):
    for j in range(m) :
        if pi[i] <= li[j] and qi[i] >= ri[j]:
            cnt += 1
    print(cnt)
    cnt = 0

Submission status: Time Limit Exceeded

Solution code:
N,M,Q=map(int,input().split())
L,R,P,C=[],[],[],[]
for i in range(M):
	l,r=map(int,input().split())
	L.append(l)
	R.append(r)
for i in range(Q):
	count=0
	p,q1=map(int,input().split())
	for j in range(M):
		if L[j]>=p and q1>=R[j]:
			count+=1
	C.append(count)
for i in range(Q):
	print(C[i])

Submission status: Time Limit Exceeded

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

range_array = [[0 for _ in range(N)] for _ in range(N)]
ans = [[0 for _ in range(N)] for _ in range(N)]

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

for i in range(N):
    sum = 0
    for j in range(N):
        sum += range_array[i][j]
        range_array[i][j] = sum
'''
for i in range(N):
    for j in range(i, N):
        sum = 0
        for k in range(i, j + 1):
            sum += range_array[k][j]
        ans[i][j] = sum
'''
for _ in range(Q):
    p, q = map(int, input().split())
    p -= 1
    q -= 1
    sum = 0
    for k in range(p, q + 1):
        sum += range_array[k][q]
    print(sum)

Submission status: Time Limit Exceeded

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

range_array = [[0 for _ in range(N)] for _ in range(N)]
ans = [[0 for _ in range(N)] for _ in range(N)]

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

for i in range(N):
    sum = 0
    for j in range(N):
        sum += range_array[i][j]
        range_array[i][j] = sum

for i in range(N):
    for j in range(i, N):
        sum = 0
        for k in range(i, j + 1):
            sum += range_array[k][j]
        ans[i][j] = sum

for _ in range(Q):
    p, q = map(int, input().split())
    p -= 1
    q -= 1
    sum = 0
    for k in range(p, q + 1):
        sum += range_array[k][q]
    print(sum)

Submission status: Time Limit Exceeded

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

range_array = [[0 for _ in range(N)] for _ in range(N)]
ans = [[0 for _ in range(N)] for _ in range(N)]

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

for i in range(N):
    sum = 0
    for j in range(N):
        sum += range_array[i][j]
        range_array[i][j] = sum

for i in range(N):
    for j in range(i, N):
        sum = 0
        for k in range(i, j + 1):
            sum += range_array[k][j]
        ans[i][j] = sum

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

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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


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


for i in range(qq):
    p,q = map(int,input().split())
    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: Time Limit Exceeded

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

temp = [ [0 for _ in range(n)] for _ in range(n)]
tables = [ [0 for _ in range(n)] for _ in range(n)]

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

pq = [tuple(int(x) - 1 for x in input().split()) for _ in range(q)]

for i in range(n):
    for j in range(n):
        tables[i][j] = sum(temp[i][:j + 1])

for p, q in pq:
    ans = 0
    if p > 0:
        for i in range(p, q + 1):
            ans += tables[i][q] - tables[i][p - 1]
    else:
        for i in range(q + 1):
            ans += tables[i][q]
    print(ans)

Submission status: Time Limit Exceeded

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

temp = [ [0 for _ in range(n)] for _ in range(n)]
tables = [ [0 for _ in range(n)] for _ in range(n)]

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

pq = [tuple(int(x) - 1 for x in input().split()) for _ in range(q)]

for i in range(n):
    hoge = 0
    for j in range(n):
        hoge += temp[i][j]
        tables[i][j] = hoge

for p, q in pq:
    ans = 0
    if p > 0:
        for i in range(p, q + 1):
            ans += tables[i][q] - tables[i][p - 1]
    else:
        for i in range(q + 1):
            ans += tables[i][q]
    print(ans)

Submission status: Time Limit Exceeded

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

tables = [ [0 for _ in range(n)] for _ in range(n)]

def incl(n):
    return n + 1

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

pq = [tuple(int(x) - 1 for x in input().split()) for _ in range(q)]

for p, q in pq:
    ans = 0
    if p > 0:
        for i in range(p, q + 1):
            ans += tables[i][q] - tables[i][p - 1]
    else:
        for i in range(q + 1):
            ans += tables[i][q]
    print(ans)

Submission status: Time Limit Exceeded

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

pq = []

for _ in range(Q):
    q1, q2 = map(int, input().split())
    pq += [[q1, q2]]

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

for p1, p2 in pq:
    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-1][p1-1])

Submission status: Time Limit Exceeded

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

lr = [tuple(int(x) for x in input().split()) for _ in range(m)]
pq = [tuple(int(x) for x in input().split()) for _ in range(q)]

for p, q in pq:
    print(sum(p <= l and q >= r for l, r in lr))

Submission status: Time Limit Exceeded

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-1][p1-1])

Submission status: Time Limit Exceeded

Solution code:
N, M, Q = [int(i) for i in input().split()]
trainDict = {}
for _ in range(M):
    l, r = [int(i) for i in input().split()]
    if l in trainDict:
        trainDict[l].append(r)
    else:
        trainDict[l] = [r]

keys = sorted(trainDict.keys())
for _ in range(Q):
    p, q = [int(i) for i in input().split()]
    ans = 0
    for key in keys:
        if key > q:
            break
        if key >= p:
            ans += len([i for i in trainDict[key] if i <= q])
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
N, M, Q = [int(i) for i in input().split()]
trainDict = {}
for _ in range(M):
    l, r = [int(i) for i in input().split()]
    if l in trainDict:
        trainDict[l].append(r)
    else:
        trainDict[l] = [r]

keys = sorted(trainDict.keys())
for _ in range(Q):
    p, q = [int(i) for i in input().split()]
    ans = 0
    for key in keys:
        if key >= p:
            ans += len([i for i in trainDict[key] if i <= q])
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
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)],dtype=np.uint32)
for (l,r) in rails:
    xlist[l-1,r-1]+=1

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


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

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

for _ in range(Q):
    p1, p2 = map(int, input().split())
    print(np.sum(mp[p1:p2+1, p1:p2+1]))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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

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

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

    for _ in range(Q):
        p1, p2 = map(int, input().split())
        print(np.sum(n_list[p1:p2+1, p1:p2+1]))

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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

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

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

    for _ in range(Q):
        p1, p2 = map(int, input().split())
        #print(p1, p2)
        print(np.sum(n_list[p1:p2+1, p1:p2+1]))

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

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

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

    question_list = []

    for _ in range(Q):
        ans = 0

        p1, p2 = map(int, input().split())

        p1, p2

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

        print(n_exp)

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

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

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

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

    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][p1:p2+1])

        print(n_exp)

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

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

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

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

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

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

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

    for q in question_list:
        ans = 0

        p1, p2 = q[:]
        for l in express_list:
            l1, l2 = l[:]
            if p1 <= l1 and p2 >= l2:
                ans += 1

        print(ans)



if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

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

L = [0 for i in range(M)]
R = [0 for i in range(M)]
p = [0 for i in range(Q)]
q = [0 for i in range(Q)]

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

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

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

for ans in anslist:
    print(ans)

Submission status: Time Limit Exceeded

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

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

Solution code:
# coding: utf-8

n,m,q = list(map(int,input().split()))
M = [ list(map(int,input().split())) for i in range(m) ]
Q = [ list(map(int,input().split())) for i in range(q) ]

count = [0]*q

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

for i in range(q):
    print(count[i])

Submission status: Time Limit Exceeded

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
    # LR = np.zeros((N + 1, N + 1), dtype='uint32')
    # LR[2][3] = 1
    # LR[3][5] = 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)

Submission status: Time Limit Exceeded

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

# 累積和
c = [[0 for _ in range(N+1)] for _ in range(N)]
for i in range(N):
    c[i][0] = 0
    for j in range(1, N+1):
        c[i][j] = c[i][j-1] + train[i][j-1]

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

Submission status: Time Limit Exceeded

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):
    ac = 0
    for j in range(n):
        lr[i][j+1] += lr[i][j]

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import collections

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

for _ in range(r):
    x,y = list(map(int,input().split()))
    R.append(str(t*y+x))

C = collections.Counter(R)

for i in range(q):
    x,y = list(map(int,input().split()))
    z = 0
    for a in range(x,y+1):
        for b in range(x,y+1):
            z += C[str(t*b+a)]
    print(z)

Submission status: Time Limit Exceeded

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

for _ in range(r):
    x,y = map(int,input().split())
    R.append(t*y+x)

for i in range(q):
    x,y = map(int,input().split())
    z = 0
    for a in range(x,y+1):
        for b in range(x,y+1):
            z += R.count(t*b+a)
    print(z)

Submission status: Time Limit Exceeded

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

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

for i in range(q):
    x,y = list(map(int,input().split()))
    z = 0
    for a in range(x,y+1):
        for b in range(x,y+1):
            z += R.count(t*b+a)
    
    print(z)

Submission status: Time Limit Exceeded

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

for _ in range(r):
    x,y = list(map(int,input().split()))
    R.append(t*y+x)
    
g = []

for i in range(q):
    x,y = list(map(int,input().split()))
    z = 0
    for a in range(x,y+1):
        for b in range(x,y+1):
            z += R.count(t*b+a)
    g.append(z)

for i in g:
    print(i)

Submission status: Time Limit Exceeded

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 i in range(q):
    x = list(map(int,input().split()))
    x.append(i)
    Q.append(x)

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

c = 0

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

Q.sort(key=lambda x:(x[2]))

for i in Q:
    print(i[3])

Submission status: Time Limit Exceeded

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

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


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

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

Submission status: Time Limit Exceeded

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

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

for i in range(q):
    l, r = map(int, input().split())
    cnt = 0
    for j in range(l, r+1):
        cnt += c[j][r] - c[j][l-1]
    print(cnt)

Submission status: Time Limit Exceeded

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

for i in range(q):
    l, r = map(int, input().split())
    cnt = 0
    for j in range(l,r+1):
        for k in range(l, r+1):
            cnt += c[j][k]
    print(cnt)

Submission status: Time Limit Exceeded

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

LRList = [[int(_) for _ in input().split()] for _ in range(M)]
PQList = [[int(_) for _ in input().split()] for _ in range(Q)]

for pq in PQList:
  ans = 0
  p,q = pq
  for lr in LRList:
    l,r = lr
    if p <=l and q >= r:
      ans += 1
  print(ans)

Submission status: Time Limit Exceeded

Solution code:
input_s = str(input())
[l, m, q] = list(map(int, input_s.split(" ")))
rosen = []
for i in range(0,m):
    input_tmp = str(input())
    rosen.append(list(map(int, input_tmp.split(" "))))
results = []
for i in range(0, q):
    result = 0
    input_tmp = str(input())
    list_tmp = list(map(int, input_tmp.split(" ")))
    result = [r for r in rosen if list_tmp[0] <= r[0] and r[1] <= list_tmp[1]]
    results.append(result)

for result in results:
    print(len(result))

Submission status: Time Limit Exceeded

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

for i in range(q):
    l, r = map(int, input().split())
    cnt = 0
    for i in range(m):
        if l <= a[i][0] and  r >= a[i][1]:
            cnt += 1
    print(cnt)