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: Runtime Error

Solution code:
from operator import itemgetter

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

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

trains.sort(key=itemgetter(1))
trains.sort(key=itemgetter(0))
index = [-1 for _ in range(n+1)]
index[trains[0][0]] = 0
tmp = trains[0][0]

num = 0
for i in range(1, len(trains)):
  i -= num
  if trains[i] == trains[i-1]:
    del trains[i]
    num += 1
  if tmp != trains[i][0]:
    tmp = trains[i][0]
    index[tmp] = i
    
for i in range(len(index)-2, 0, -1):
    if index[i] == -1:
      index[i] = index[i+1]

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

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

Submission status: Runtime Error

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

count_list=[0,]
i=0
for a in q_list:
    count_list[i]=0
    for b in l_list:
        if a[0]<=b[0] and a[1]>=b[1]:
            count_list[i]+=1
    i+=1
            
i=0
for i in range(q):
    print(count_list[i])

Submission status: Runtime Error

Solution code:
N, M, Q = map(int, input().split())
tL = []
tR = []
for i in range(M):
    a, b = map(int, input().split())
    tL.append(a)
    tR.append(b)
ql = []
qr = []
for j in range(Q):
    c, d = map(int, input().split())
    ql.append(c)
    qr.append(d)

for j in range(Q):
    count = 0
    for i in range(M):
        if ql[j] => tL[i] or tR[i] => qr[j]:
            continue
        else:
            count += 1
    print(count)

Submission status: Runtime Error

Solution code:
import bisect
import numpy

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

trains = numpy.array([[0, 0] for i in range(M)])
for i in range(M):
	trains[i][0], trains[i][1] = map(int, input().split())

for i in range(M):
	p, q = map(int, input().split())
	trains_L = trains[:,0]
	L_index = bisect.bisect_left(trains_L, p)
	ans_L = numpy.array(sorted(trains[L_index:], key=lambda x: x[1]))
	trains_R = ans_L[:,1]
	R_index = bisect.bisect_right(trains_R, q)
	ans = ans_L[:R_index]
	print(len(ans))

Submission status: Runtime Error

Solution code:
N, M, Q = map(int, input().split())
trains = {}
answers = {}
results = []
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())
    train = make_range(a, b)
    if train in trains:
        trains[train] += 1
    else:
        trains[train] = 1
    
def combine_answer(answers, question, res):
    for other_question in answers:
        combine_question = other_question + question
        if other_question | question == combine_question:
            combine_res = answers[other_question] + res
            combine_answer(answers, combine_question, combine_res)
            answers[combine_question] = combine_res

for i in range(Q):
    a, b = map(int, input().split())
    question = make_range(a, b)
    if question in answers:
        results.append(answers[question])
    else:
        res = 0
        for train in trains:
            if question | train == question:
                res += trains[train]
        combine_answer(answers, question, res)
        answers[question] = res
        results.append(res)

for result in results:
    print(result)

Submission status: Runtime Error

Solution code:
n,m,q = input().split()
n = int(n)
m = int(m)
q = int(q)
list_r = []
list_l = []
l = []
r = []
for i in range(m):
    l,r = input().split()
    list_l.append(int(l))
    list_r.append(int(r))
for j in range(q):
    num = 0
    p,q = input().split()
    p = int(p)
    q = int(q)
    for k in range(m):
        if list_l[0] < p:
            list_l.pop(0)
            list_r.pop(0)
        else:
            break
    index_p = m - len(list_l)
    for k in range(len(list_l)):
        if p <= list_l[k] and list_r[k] <= q:
            num += 1
        else:
            pass
    print(num)

Submission status: Runtime Error

Solution code:
from collections import deque
n,m,q = map(int, input().split())
astart = []
aend = []
bstart = []
bend = []
ans = []
for i in xrange(m):
    a1,a2 = map(int, input().split())
    astart.append(a1)
    aend.append(a2)
for i in xrange(q):
    a1,a2 = map(int, input().split())
    bstart.append(a1)
    bend.append(a2)
cstart = deque(bstart)
cend = deque(bend)
while len(cstart) > 0:
    count = 0
    s = cstart.popleft()
    e = cend.popleft()
    for i in range(0,m):
        if s <= astart[i] and e >=aend[i]:
            count+=1
        if i == m-1:
            print(count)

Submission status: Runtime Error

Solution code:
n,m,q = map(int, input().split())
astart = []
aend = []
bstart = []
bend = []
ans = []
for i in range(m):
    a1,a2 = map(int, input().split())
    astart.append(a1)
    aend.append(a2)
for i in range(q):
    a1,a2 = map(int, input().split())
    bstart.append(a1)
    bend.append(a2)
cstart = deque(bstart)
cend = deque(bend)
while len(cstart) > 0:
    count = 0
    s = cstart.popleft()
    e = cend.popleft()
    for i in range(0,m):
        if s <= astart[i] and e >=aend[i]:
            count+=1
        if i == m-1:
            print(count)

Submission status: Runtime Error

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], x[1]))
L = list(map(lambda x: x[0], LR))
#print(LR)

C = [[0]*(m+1) for _ in range(m+1)]
for i in range(1,m+1):
    l = bisect_left(L, i)
    r = bisect_left(L, i+1)-1
    R2 = list(map(lambda x: x[1], LR[l:r+1]))
    #print(l, r, R2)
    for j in range(i,m+1):
        C[i][j] = bisect_left(R2, j+1)
    #print(i, C[i])

for i in range(q):
    ans = 0
    for j in range(P[i], Q[i]+1):
        ans += C[j][Q[i]]
    print(ans)

Submission status: Runtime Error

Solution code:
def binarySearch(D, target):
    left = 0
    right = len(D)
    while left < right:
        mid = (left + right) // 2
        if D[mid] == target:
            return mid
        elif target < D[mid]:
            right = mid
        else:
            left = mid + 1
    return mid

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

# sortしておく
for i in range(N):
    LR[i].sort()

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 += binarySearch(LR[j], q) + 1
    print(re)

Submission status: Runtime Error

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

for t in range(Q):
    for i in range(M):
        count+=1 if p_q[t][0] <= L_R[i][0] and p_q[t][1] >= L_R[i][1] else 0
print(count)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(10000)


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


class SegmentTree():
    # to par: (n-1) // 2
    # to chr: 2n+1, 2n+2
    def __init__(self, N):
        self.__N = 2**int(math.ceil(math.log(N, 2)))
        self.__table = [0 for _ in range(self.__N * 2 - 1)]

    def update(self, idx, x):
        i = self.__N - 1 + idx  # target leaf
        self.__table[i] += 1
        while i != 0:
            pi = (i - 1) // 2  # parent
            self.__table[pi] += self.__table[i]
            i = pi

    def __query(self, a, b, k, l, r):
        if r <= a or b <= l:
            return 0
        if a <= l and r <= b:
            return self.__table[k]

        vl = self.__query(a, b, 2 * k + 1, l, (l + r) // 2)
        vr = self.__query(a, b, 2 * k + 2, (l + r) // 2, r)

        return vl + vr

    def query(self, a, b):
        return self.__query(a, b, 0, 0, self.__N)

    def print(self):
        print(self.__table)


@mt
def slv(N, M, Q, LR, PQ):

    ts = SegmentTree(N)
    te = SegmentTree(N)
    for i, (l, r) in enumerate(LR):
        ts.update(l, i)
        te.update(r, i)

    for p, q in PQ:
        ls = ts.query(0, p)
        re = te.query(q+1, N+1)
        print(ls, re)
        print(M-(ls+re))


def main():
    N, M, Q = read_int_n()
    LR = [read_int_n() for _ in range(M)]
    PQ = [read_int_n() for _ in range(Q)]
    slv(N, M, Q, LR, PQ)

    # N = 500
    # M = 2*(10**5)
    # Q = 10**5
    # LR = []
    # for _ in range(M):
    #     s = random.randint(1, N+1)
    #     e = random.randint(1, N+1)
    #     if s > e:
    #         s, e = e, s
    #     LR.append((s, e))
    # PQ = []
    # for _ in range(Q):
    #     s = random.randint(1, N+1)
    #     e = random.randint(1, N+1)
    #     if s > e:
    #         s, e = e, s
    #     PQ.append((s, e))
    # slv(N, M, Q, LR, PQ)


if __name__ == '__main__':
    main()

Submission status: Runtime Error

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, 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]]))
    # print((ls >= ps)[rs <= qs])
    for count in np.sum((ls >= ps) * (rs <= qs),axis=1):
        print(count)
    return 0


abc106_d()

Submission status: Runtime Error

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

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

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

Submission status: Runtime Error

Solution code:
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)
    
for i in range(Q):
    answer=0
    for j in range(m):
        if p[i]<=l[j] and r[j]<=q[i]:
            answer+=1
    print(answer)

Submission status: Runtime Error

Solution code:
from operator import itemgetter

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

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

trains.sort(key=itemgetter(0))
index = [-1 for _ in range(n+1)]
index[trains[0][0]] = 0
tmp = trains[0][0]

for i in range(len(trains)):
  if tmp != trains[i][0]:
    tmp = trains[i][0]
    index[tmp] = i
    
for i in range(len(index)-1, 0, -1):
    if index[i] == -1:
      index[i] = index[i+1]

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[index[question[0]]:]:
    if train[0] < question[0]:
      continue
    if train[1] > question[1]:
      continue
    cnt += 1
    
  print(cnt)

Submission status: Runtime Error

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 t in range(q):
    count=0
    blist=[]
    p,q=map(int,input().split())
    for j in range (len(alist)):
        if p<=alist[0][0]:
            alist.sort(key=lambda x:x[1])
            break
        alist.remove(alist[0])
        blist.append(alist[0])
    for j in range (len(alist)):
        if q>=alist[j][1]:
            count+=1
        else:
            break
    for k in blist:
        alist.append(k)
    print(count)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
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: Runtime Error

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


import numpy as np
ar = np.zeros([M, N])
for m in range(M):
    ar[m, LR[m][0]:LR[m][1]] = 1

for q in range(Q):
    left = PQ[q][0]
    right = PQ[q][1]
    if left != 0 and right!=9:
        flag = (ar[:, left-1] == 0)* (ar[:, right+1] == 0) * (ar[:, left:right+1].max(axis=1) > 0)
        print(sum(flag))
    elif left == 0 and right!=9:
        flag = (ar[:, right+1] == 0) * (ar[:, left:right+1].max(axis=1) > 0)
        print(sum(flag))
    elif left != 0 and right==9:
        flag = (ar[:, left-1] == 0) * (ar[:, left:right+1].max(axis=1) > 0)
        print(sum(flag))
    else:
        print(M)

Submission status: Runtime Error

Solution code:
#include <bits/stdc++.h>
using namespace std;
int A,B,C;
vector<int>X1,X2,Y1,Y2;
int main(){
    cin>>A>>B>>C;
    for(int i=0;i<B;i++){
        int x,y;
        cin>>x>>y;
        X1.push_back(x);
        Y2.push_back(-y);
    }
    sort(X1.begin(),X1.end());
    sort(Y2.begin(),Y2.end());
    while(C--){
        int x,y;
        cin>>x>>y;
        // x 왼쪽
        int x1 = upper_bound(Y2.begin(),Y2.end(),-x) - Y2.begin();
        x1 = B - x1;
        // x 오른쪽
        int x2 = lower_bound(X1.begin(),X1.end(),x) - X1.begin();
        x2 = B - x2;
        // y 오른쪽
        int y1 = upper_bound(X1.begin(),X1.end(),y) - X1.begin();
        y1 = B - y1;
        // y 왼쪽
        int y2 = lower_bound(Y2.begin(),Y2.end(),-y) - Y2.begin();
        y2 = B - y2;
        cout<< x2 + y2 - ( B - x1 - y1 ) <<'\n';
    }
    return 0;
}

Submission status: Runtime Error

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


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

Submission status: Runtime Error

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+=f'{dp[p][q]}\n'
print(ans[:-1])

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(10000)


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


class SegmentTree():
    # to par: (n-1) // 2
    # to chr: 2n+1, 2n+2
    def __init__(self, N):
        self.__N = 2**int(math.ceil(math.log(N, 2)))
        self.__table = [[] for _ in range(self.__N * 2 - 1)]

    def update(self, idx, x):
        i = self.__N - 1 + idx  # target leaf
        self.__table[i].append(x)
        while i != 0:
            pi = (i - 1) // 2  # parent
            self.__table[pi].append(x)
            # if self.__table[i] < self.__table[pi]:
            #     self.__table[pi] = self.__table[i]
            # else:
            #     break
            i = pi

    def __query(self, a, b, k, l, r):
        if r <= a or b <= l:
            return []
        if a <= l and r <= b:
            return self.__table[k]

        vl = self.__query(a, b, 2 * k + 1, l, (l + r) // 2)
        vr = self.__query(a, b, 2 * k + 2, (l + r) // 2, r)

        return vl + vr

    def query(self, a, b):
        return self.__query(a, b, 0, 0, self.__N)

    def print(self):
        print(self.__table)


@mt
def slv(N, M, Q, LR, PQ):

    st = SegmentTree(N)
    for i, (l, r) in enumerate(LR):
        st.update(l, i)
        st.update(r, i)

    for p, q in PQ:
        l = st.query(p, q+1)
        n = len(l)
        m = len(set(l))
        print(n-m)


def main():
    N, M, Q = read_int_n()
    LR = [read_int_n() for _ in range(M)]
    PQ = [read_int_n() for _ in range(Q)]
    slv(N, M, Q, LR, PQ)


if __name__ == '__main__':
    main()

Submission status: Runtime Error

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(int(q)):
    count = 0
    for j in range(int(m)):
        if plist[i] <= llist[j] and qlist[i] >= rlist[j]:
            count += 1
    print(count)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(10000)


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


class SegmentTree():
    # to par: (n-1) // 2
    # to chr: 2n+1, 2n+2
    def __init__(self, N):
        self.__N = 2**int(math.ceil(math.log2(N)))
        self.__table = [[] for _ in range(self.__N * 2 - 1)]

    def update(self, idx, x):
        i = self.__N - 1 + idx  # target leaf
        self.__table[i].append(x)
        while i != 0:
            pi = (i - 1) // 2  # parent
            self.__table[pi].append(x)
            # if self.__table[i] < self.__table[pi]:
            #     self.__table[pi] = self.__table[i]
            # else:
            #     break
            i = pi

    def __query(self, a, b, k, l, r):
        if r <= a or b <= l:
            return []
        if a <= l and r <= b:
            return self.__table[k]

        vl = self.__query(a, b, 2 * k + 1, l, (l + r) // 2)
        vr = self.__query(a, b, 2 * k + 2, (l + r) // 2, r)

        return vl + vr

    def query(self, a, b):
        return self.__query(a, b, 0, 0, self.__N)

    def print(self):
        print(self.__table)


@mt
def slv(N, M, Q, LR, PQ):

    st = SegmentTree(N)
    for i, (l, r) in enumerate(LR):
        st.update(l, i)
        st.update(r, i)

    for p, q in PQ:
        l = st.query(p, q+1)
        n = len(l)
        m = len(set(l))
        print(n-m)


def main():
    N, M, Q = read_int_n()
    LR = [read_int_n() for _ in range(M)]
    PQ = [read_int_n() for _ in range(Q)]
    slv(N, M, Q, LR, PQ)


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import numpy
N, M, Q = map(int, input().split())
l = [0]*(N+1)
r = [0]*(N+1)
for _ in range(M):
    a, b = map(int, input().split())
    l[a] -= 1
    r[b-1] += 1
l = numpy.cumsum(l)
r = numpy.cumsum(r)

for _ in range(Q):
    a, b = map(int, input().split())
    print(append(r[b-1] + l[a-1]))

Submission status: Runtime Error

Solution code:
N, M, Q = map(int, raw_input().split())
for _ in range(M):
LR = [map(int, raw_input().split()) for _ in range(M)]
pq = [map(int, raw_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[LR[0]][LR[1]] += 1
for question in pq:
    p = question[0]
    q = question[1]
    ans = 0
    for j in range(p, q+1):
        ans += table[p][j]
    print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
#include<iostream>
#include<algorithm>
#include<math.h>
#include<queue>
#include<string>
#include<vector>
#include<stack>
#include<iomanip>
#include<map>
#define rep(i,n) for(int i=0;i<((int)n);i++)
#define drep(i,n) for(int i=((int)n)-1;i>-1;i--)
#define Rep(i,n0,n) for(int i=n0;i<((int)n);i++)
#define Com(i,j,n) for(int i=0;i<n-1;i++)for(int j=i+1;j<((int)n);j++)
#define W(x) cout<<x<<endl;
#define Debug(x) cout<<"#DEBUG "<<x<<endl;
#define INF (1<<29)
#define INF2 (long long)8*(long long)INF*(long long)INF
#define mod 1000000007

typedef long long ll;

using namespace std;


int min(int x,int y){if(y<x)return y;else return x;}
int max(int x,int y){if(y>x)return y;else return x;}
int fact(int x){int i=1;rep(j,x){i*=(j+1);} return i;}
long long fact(long long x){long long i=1;rep(j,x){i*=(j+1);} return i;}
int gcd(int x, int y){if(x%y==0)return y;else if(y%x==0)return x;else return gcd(x%y,y%x);}
ll gcd(ll x, ll y){if(x%y==0)return y;else if(y%x==0)return x;else return gcd(x%y,y%x);}
void say(bool x){if(x){cout<<"Yes"<<endl;}else {cout<<"No"<<endl;}return;}

int dd[500][500],PP[2][100000];
int main()
{
    int n,m,Q;
    cin >>n >>m >>Q;
    int l,r;
    rep(i,m)
    {
        cin>>l>>r;
        l--;
        r--;
        dd[l][r]++;
    }
    rep(i,n)
    {
        rep(j,n-1)
        {
            dd[i][j+1]+=dd[i][j];
        }
    }
    rep(i,n)
    {
        drep(j,n-1)
        {
            dd[j][i]+=dd[j+1][i];
        }
    }
    int p,q;
    rep(i,Q)
    {
        cin>>p>>q;
        PP[0][i]=--p;
        PP[1][i]=--q;
    }
    rep(i,Q)
    {
        W(dd[PP[0][i]][PP[1][i]])
    }
    return 0;
}

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
#include<iostream>
#include<algorithm>
#include<math.h>
#include<queue>
#include<string>
#include<vector>
#include<stack>
#include<iomanip>
#include<map>
#define rep(i,n) for(int i=0;i<((int)n);i++)
#define drep(i,n) for(int i=((int)n)-1;i>-1;i--)
#define Rep(i,n0,n) for(int i=n0;i<((int)n);i++)
#define Com(i,j,n) for(int i=0;i<n-1;i++)for(int j=i+1;j<((int)n);j++)
#define W(x) cout<<x<<endl;
#define Debug(x) cout<<"#DEBUG "<<x<<endl;
#define INF (1<<29)
#define INF2 (long long)8*(long long)INF*(long long)INF
#define mod 1000000007

typedef long long ll;

using namespace std;


int min(int x,int y){if(y<x)return y;else return x;}
int max(int x,int y){if(y>x)return y;else return x;}
int fact(int x){int i=1;rep(j,x){i*=(j+1);} return i;}
long long fact(long long x){long long i=1;rep(j,x){i*=(j+1);} return i;}
int gcd(int x, int y){if(x%y==0)return y;else if(y%x==0)return x;else return gcd(x%y,y%x);}
ll gcd(ll x, ll y){if(x%y==0)return y;else if(y%x==0)return x;else return gcd(x%y,y%x);}
void say(bool x){if(x){cout<<"Yes"<<endl;}else {cout<<"No"<<endl;}return;}

int dd[500][500];
int main()
{
    int n,m,Q;
    cin >>n >>m >>Q;
    int l,r;
    rep(i,m)
    {
        cin>>l>>r;
        l--;
        r--;
        dd[l][r]++;
    }
    rep(i,n)
    {
        rep(j,n-1)
        {
            dd[i][j+1]+=dd[i][j];
        }
    }
    rep(i,n)
    {
        drep(j,n-1)
        {
            dd[j][i]+=dd[j+1][i];
        }
    }
    int p,q;
    rep(i,Q)
    {
        cin>>p>>q;
        p--;
        q--;
        W(dd[p][q])
    }
    return 0;
}

Submission status: Runtime Error

Solution code:
n,m,q=map(int,raw_input().split())
lrs=[map(int,raw_input().split()) for _ in range(m)]
a=[[0 for j in range(n)] for i in range(n)]
for l,r in lrs:a[l-1][r-1]+=1
cnt=[[0 for j in range(n)] for i in range(n)]
for y in range(n):
 v = 0
 for x in range(y+1):
  v+=a[x][y]
  cnt[x][y]=cnt[x][y-1]+v
for _ in range(q):
 l,r=map(int,raw_input().split())
 print cnt[l][r]