Problem:


Score: 400 points

Problem Statement

In Takahashi Kingdom, there is a east-west railroad and N cities along it, numbered 1, 2, 3, ..., N from west to east.
A company called AtCoder Express possesses M trains, and the train i runs from City L_i to City R_i (it is possible that L_i = R_i).
Takahashi the king is interested in the following Q matters:

The number of the trains that runs strictly within the section from City p_i to City q_i, that is, the number of trains j such that p_i \leq L_j and R_j \leq q_i.

Although he is genius, this is too much data to process by himself. Find the answer for each of these Q queries to help him.

Constraints

N is an integer between 1 and 500 (inclusive).

M is an integer between 1 and 200 \ 000 (inclusive).

Q is an integer between 1 and 100 \ 000 (inclusive).

1 \leq L_i \leq R_i \leq N (1 \leq i \leq M)

1 \leq p_i \leq q_i \leq N (1 \leq i \leq Q)

Input

Input is given from Standard Input in the following format:

N M Q
L_1 R_1
L_2 R_2
:
L_M R_M
p_1 q_1
p_2 q_2
:
p_Q q_Q

Output

Print Q lines. The i-th line should contain the number of the trains that runs strictly within the section from City p_i to City q_i.

Sample Input 1

2 3 1
1 1
1 2
2 2
1 2

Sample Output 1

3

As all the trains runs within the section from City 1 to City 2, the answer to the only query is 3.

Sample Input 2

10 3 2
1 5
2 8
7 10
1 7
3 10

Sample Output 2

1
1

The first query is on the section from City 1 to 7. There is only one train that runs strictly within that section: Train 1.
The second query is on the section from City 3 to 10. There is only one train that runs strictly within that section: Train 3.

Sample Input 3

10 10 10
1 6
2 9
4 5
4 7
4 7
5 8
6 6
6 7
7 9
10 10
1 8
1 9
1 10
2 8
2 9
2 10
3 8
3 9
3 10
1 10

Sample Output 3

7
9
10
6
8
9
6
7
8
10



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


Sample output:
3

Submission status: Wrong Answer

Solution code:
import numpy as np
import copy

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

train_map = np.zeros((n, n), dtype=np.int)
s = copy.deepcopy(train_map)
numbers = []

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

for i in range(n):
    tmp = 0
    for j in range(n):
        tmp += train_map[i][j]
        s[i][j] = tmp

for i in range(q):
    st, go = map(int, input().split())
    number = 0
    for j in range(st-1, go):
        if st ==1:
            number += s[j][go-1]
            continue
        number += s[j][go-1] - s[j][st-2]

    numbers.append(number)

exit()

print(train_map[0][0])


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

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

s = copy.deepcopy(train_map)

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

for i in range(n):
    tmp = 0
    for j in range(n):
        tmp += train_map[i][j]
        s[i][j] = tmp

exit()

for i in range(q):
    st, go = map(int, input().split())
    number = 0
    """
    for j in range(st-1, go):
        if st ==1:
            number += s[j][go-1]
            continue
        number += s[j][go-1] - s[j][st-2]
    """
    numbers.append(number)

for num in numbers:
    print(num)

Submission status: Wrong Answer

Solution code:
import numpy as np
import copy

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

train_map = np.zeros((n, n), dtype=np.int)
s = copy.deepcopy(train_map)
numbers = []

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

for i in range(n):
    tmp = 0
    for j in range(n):
        tmp += train_map[i][j]
        s[i][j] = tmp

for i in range(q):
    st, go = map(int, input().split())
    number = 0
    """
    for j in range(st-1, go):
        if st ==1:
            number += s[j][go-1]
            continue
        number += s[j][go-1] - s[j][st-2]
    """
    numbers.append(number)

exit()

print(train_map[0][0])


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

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

s = copy.deepcopy(train_map)

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

for i in range(n):
    tmp = 0
    for j in range(n):
        tmp += train_map[i][j]
        s[i][j] = tmp

exit()

for i in range(q):
    st, go = map(int, input().split())
    number = 0
    """
    for j in range(st-1, go):
        if st ==1:
            number += s[j][go-1]
            continue
        number += s[j][go-1] - s[j][st-2]
    """
    numbers.append(number)

for num in numbers:
    print(num)

Submission status: Wrong Answer

Solution code:
import numpy as np
import copy

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

train_map = np.zeros((n, n), dtype=np.int)
s = copy.deepcopy(train_map)

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

for i in range(n):
    tmp = 0
    for j in range(n):
        tmp += train_map[i][j]
        s[i][j] = tmp

exit()

print(train_map[0][0])


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

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

s = copy.deepcopy(train_map)

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

for i in range(n):
    tmp = 0
    for j in range(n):
        tmp += train_map[i][j]
        s[i][j] = tmp

exit()

for i in range(q):
    st, go = map(int, input().split())
    number = 0
    """
    for j in range(st-1, go):
        if st ==1:
            number += s[j][go-1]
            continue
        number += s[j][go-1] - s[j][st-2]
    """
    numbers.append(number)

for num in numbers:
    print(num)

Submission status: Wrong Answer

Solution code:
import numpy as np
import copy

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

train_map = np.zeros((n, n), dtype=np.int)
s = copy.deepcopy(train_map)

exit()

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

exit()

print(train_map[0][0])


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

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

s = copy.deepcopy(train_map)

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

for i in range(n):
    tmp = 0
    for j in range(n):
        tmp += train_map[i][j]
        s[i][j] = tmp

exit()

for i in range(q):
    st, go = map(int, input().split())
    number = 0
    """
    for j in range(st-1, go):
        if st ==1:
            number += s[j][go-1]
            continue
        number += s[j][go-1] - s[j][st-2]
    """
    numbers.append(number)

for num in numbers:
    print(num)

Submission status: Wrong Answer

Solution code:
import numpy as np
import copy

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

train_map = np.zeros((n, n), dtype=np.int)
s = copy.deepcopy(train_map)

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

exit()

print(train_map[0][0])


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

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

s = copy.deepcopy(train_map)

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

for i in range(n):
    tmp = 0
    for j in range(n):
        tmp += train_map[i][j]
        s[i][j] = tmp

exit()

for i in range(q):
    st, go = map(int, input().split())
    number = 0
    """
    for j in range(st-1, go):
        if st ==1:
            number += s[j][go-1]
            continue
        number += s[j][go-1] - s[j][st-2]
    """
    numbers.append(number)

for num in numbers:
    print(num)

Submission status: Wrong Answer

Solution code:
import copy

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

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

s = copy.deepcopy(train_map)

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

for i in range(n):
    tmp = 0
    for j in range(n):
        tmp += train_map[i][j]
        s[i][j] = tmp

exit()

for i in range(q):
    st, go = map(int, input().split())
    number = 0
    """
    for j in range(st-1, go):
        if st ==1:
            number += s[j][go-1]
            continue
        number += s[j][go-1] - s[j][st-2]
    """
    numbers.append(number)

for num in numbers:
    print(num)

Submission status: Wrong Answer

Solution code:
import copy

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

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

s = copy.deepcopy(train_map)

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

for i in range(n):
    tmp = 0
    for j in range(n):
        tmp += train_map[i][j]
        s[i][j] = tmp

exit()

for i in range(q):
    st, go = map(int, input().split())
    number = 0
    """
    for j in range(st-1, go):
        if st ==1:
            number += s[j][go-1]
            continue
        number += s[j][go-1] - s[j][st-2]
    """
    numbers.append(number)

for num in numbers:
    print(num)

Submission status: Wrong Answer

Solution code:
import copy

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

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

s = copy.deepcopy(train_map)

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

for i in range(n):
    tmp = 0
    for j in range(n):
        tmp += train_map[i][j]
        s[i][j] = tmp

for i in range(q):
    st, go = map(int, input().split())
    number = 0
    """
    for j in range(st-1, go):
        if st ==1:
            number += s[j][go-1]
            continue
        number += s[j][go-1] - s[j][st-2]
    """
    numbers.append(number)

for num in numbers:
    print(num)

Submission status: Wrong Answer

Solution code:
import copy

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

train_map = []
numbers = []

for i in range(n):
    train_map.append([])
    for j in range(n):
        train_map[i].append(0)

s = copy.deepcopy(train_map)

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

for i in range(n):
    tmp = 0
    for j in range(n):
        tmp += train_map[i][j]
        s[i][j] = tmp

for i in range(q):
    st, go = map(int, input().split())
    number = 0
    for j in range(st-1, go):
        if st ==1:
            number += s[j][go-1]
            continue
        number += s[j][go-1] - s[j][st-1]
    numbers.append(number)

for num in numbers:
    print(num)

Submission status: Wrong Answer

Solution code:
import copy

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

train_map = []
numbers = []

for i in range(n):
    train_map.append([])
    for j in range(n):
        train_map[i].append(0)

s = copy.deepcopy(train_map)

print(train_map)

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

for i in range(n):
    tmp = 0
    for j in range(n):
        tmp += train_map[i][j]
        s[i][j] = tmp

for i in range(q):
    st, go = map(int, input().split())
    number = 0
    for j in range(st-1, go):
        if st ==1:
            number += s[j][go-1]
            continue
        number += s[j][go-1] - s[j][st-1]
    numbers.append(number)

for num in numbers:
    print(num)

Submission status: Wrong Answer

Solution code:
import copy

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

train_map = []
numbers = []

for i in range(n):
    train_map.append([])
    for j in range(n):
        train_map[i].append(0)

s = copy.deepcopy(train_map)

print(train_map)

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

for i in range(n):
    tmp = 0
    for j in range(n):
        tmp += train_map[i][j]
        s[i][j] = tmp

for i in range(q):
    st, go = map(int, input().split())
    number = 0
    for j in range(st-1, go):
        if st ==1:
            number += s[j][go-1]
            continue
        number += s[j][go-1] - s[j][st-1]
    numbers.append(number)

for num in numbers:
    print(num)

print(s)

Submission status: Wrong Answer

Solution code:
import copy

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

train_map = []
numbers = []

for i in range(n):
    train_map.append([])
    for j in range(n):
        train_map[i].append(0)

s = copy.deepcopy(train_map)

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

for i in range(n):
    tmp = 0
    for j in range(n):
        tmp += train_map[i][j]
        s[i][j] = tmp

for i in range(q):
    st, go = map(int, input().split())
    number = 0
    for j in range(st-1, go):
        1
        #number += s[j][go-1]
    numbers.append(number)

for num in numbers:
    print(num)

Submission status: Wrong Answer

Solution code:
import copy

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

train_map = []
numbers = []

for i in range(n):
    train_map.append([])
    for j in range(n):
        train_map[i].append(0)

s = copy.deepcopy(train_map)

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

for i in range(n):
    tmp = 0
    for j in range(n):
        tmp += train_map[i][j]
        s[i][j] = tmp

for i in range(1):
    st, go = map(int, input().split())
    number = 0
    for j in range(st-1, go):
        number += s[j][go-1]
    numbers.append(number)

for num in numbers:
    print(num)

Submission status: Wrong Answer

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

trains = []
sections = []

for i in range(m):
    trains.append(tuple(map(int, input().split())))

print(trains)

for i in range(q):
    sections.append(tuple(map(int, input().split())))

#print(sections)

trains = sorted(trains, key=lambda x: x[0])

print(trains)

for section in sections:
    number = 0
    flag = False
    for train in trains:
        if section[0] <= train[0]:
            if train[1] <= section[1]:
                number += 1
                print('in')
            flag = True
        elif flag:
            print('out')
            continue

    print(number)

Submission status: Wrong Answer

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

trains = []
sections = []

for i in range(m):
    trains.append(tuple(map(int, input().split())))

#print(trains)

for i in range(q):
    sections.append(tuple(map(int, input().split())))

#print(sections)

for section in sections:
    number = 0
    for train in trains:
        break
        if section[0] <= train[0] and train[1] <= section[1]:
            number += 1
    print(number)

Submission status: Wrong Answer

Solution code:
import copy

N,M,Q = map(int,input().split())
LR = [[] for i in range(N+1)]
R = []
for i in range(M):
    l,r = (int(x) for x in input().split())
    LR[l] += [r]

table = [[0 for i in range(N+1)] for j in range(N+1)]
if len(LR[N]) != 0:
    table[N][N] = len(LR[N])

for l in range(1,N)[::-1]:
    table[l] = copy.copy(table[l+1])
    i,pr,temp = -1,N+1,len(LR[l])
    while i >= -len(LR[l]):
        r = LR[l][i]
        c = LR[l].count(r)
        for j in range(r,pr)[::-1]:
            table[l][j] += temp
        i -= c
        temp += c
        pr = r

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

Submission status: Wrong Answer

Solution code:
import copy

N,M,Q = map(int,input().split())
LR = [[] for i in range(N+1)]
R = []
for i in range(M):
    l,r = (int(x) for x in input().split())
    LR[l] += [r]
    R += [r]
R = sorted(R)

table = [[0 for i in range(N+1)] for j in range(N+1)]
i,pr,temp = -1,N+1,M
while i >= -M:
    r = R[i]
    c = R.count(r)
    for j in range(r,pr)[::-1]:
        table[1][j] = temp
    i -= c
    temp -= c
    pr = r

for l in range(1,N):
    if len(LR[l]) == 0:
        table[l+1] = copy.copy(table[l])
    else:
        i,pr,temp = -1,N+1,len(LR[l])
        while i >= -len(LR[l]):
            r = LR[l][i]
            c = LR[l].count(r)
            for j in range(r,pr)[::-1]:
                table[l+1][j] = table[l][j] - temp
            i -= c
            temp -= c
            pr = r
        for j in range(l,pr)[::-1]:
            table[l+1][j] = table[l][j]

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

Submission status: Wrong Answer

Solution code:
#二次元累積和
#https://tqk.hatenablog.jp/entry/ABC106-2
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)]
train = [[0] * (N + 1) for _ in range(N + 1)]
train[0][0] = 0
for L,R in LR:
    train[L][R] = 1
for l in range(1,N+1):
    for r in range(1,N+1):
        train[l][r] += train[l-1][r] + train[l][r-1] - train[l-1][r-1]
for p, q in pq:
    print(train[q][q]-train[q][p-1]-train[p-1][q]+train[p-1][p-1])

Submission status: Wrong Answer

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

import numpy as np
matrix = np.array([[0 for _ in range(N+1)] for _ in range(N+1)], dtype=np.int16)

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

for i in range(1, N+1):
    for j in range(i, N+1):
        w = pairs[i][j]
        if w > 0:
            matrix[:i+1,j:] += w

pairs = [[matrix[i,j] for j in range(N+1)] for i in range(N+1)]

Submission status: Wrong Answer

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

import numpy as np
matrix = np.array([[0 for _ in range(N+1)] for _ in range(N+1)], dtype=np.int16)

for L, R in (map(int, input().split()) for _ in range(M)):
    matrix[:L+1,R:] += 1

Submission status: Wrong Answer

Solution code:
n, m, q = map(int, input().split())
lr_array = [[int(x) for x in input().split()] for y in range(m)]
pq_array = [[int(x) for x in input().split()] for y in range(q)]


def solve1():
    table = [[0 for x in range(n + 1)] for y in range(n + 1)]
    for l, r in lr_array:
        table[l][r] += 1
    # for row in table:
    #     print(row)
    # print("---------")
    for i in range(1, n + 1):
        for j in range(1, n + 1):
            table[i][j] = table[i][j - 1] + table[i][j]
    # for row in table:
    #     print(row)
    for p, q in pq_array:
        res = 0
        for i in range(p, q + 1):
            # print(i)
            res += table[i][q]
        print(res)

    return 0


# 横軸：スタート
# 縦軸：ゴール
# 2次元累積和で解く
def solve2():
    table = [[0 for x in range(n + 1)] for y in range(n + 1)]
    for l, r in lr_array:
        table[l][r] += 1
    # for row in table:
    #     print(row)
    # print("---------")

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

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

    # p=1, q=8の場合、
    # 「スタートが8でゴールが8の場合のすべての本数」から「スタートが1の場合の
    for p, q in pq_array:
        print(table[q][q] + table[p][p] - table[q][p-1] - table[p-1][q])


if __name__ == '__main__':
    # solve1()
    solve2()

Submission status: Wrong Answer

Solution code:
from functools import partial
from itertools import islice, accumulate


def take(n, iterable):
    return list(islice(iterable, n))


def chunked(iterable, n):
    return iter(partial(take, n, iter(iterable)), [])


def solve(s):
    n, m, q, *lrpq = map(int, s.split())
    lr, pq = lrpq[:2 * m], lrpq[2 * m:]
    ls, rs = [0] * n, [0] * n
    for l, r in chunked(lr, 2):
        ls[l - 1] += 1
        rs[r - 1] += 1
    *ls, = accumulate(ls)
    *rs, = accumulate(rs)
    ls = [0] + ls
    rs = [0] + rs
    return "\n".join([str(rs[q] - rs[p - 1] - ls[p - 1]) for p, q in chunked(pq, 2)])


n, m, q = map(int, input().split())
print(solve('{} {} {}\n'.format(n, m, q) + '\n'.join([input() for _ in range(m + q)])))

Submission status: Wrong Answer

Solution code:
#D問題
N,M,Q = map(int,input().split())
LR = [list(map(int,input().split())) for i in range(M)]
PQ = [list(map(int,input().split())) for i in range(Q)]
DN = [[0 for j in range(N)] for i in range(N)]

for i in range(M):
    l = LR[i][0]
    r = LR[i][1]
    DN[l-1][r-1]+=1

ans = 0
for i in range(Q):
    p = PQ[i][0]
    q = PQ[i][1]
    for j in range(q-p+1):
        P = DN[p+j-1]
        ans+=sum(P[p-1:q])
    print(ans)

Submission status: Wrong Answer

Solution code:
#D問題
N,M,Q = map(int,input().split())
LR = [list(map(int,input().split())) for i in range(M)]
PQ = [list(map(int,input().split())) for i in range(Q)]
DN = [[0 for j in range(N)] for i in range(N)]

for i in range(M):
    l = LR[i][0]
    r = LR[i][1]
    DN[l-1][r-1]+=1

ans = 0
for i in range(Q):
    p = PQ[i][0]
    q = PQ[i][1]
    for j in range(q-p+1):
        P = DN[p+j-1]
        ans+=sum(P[p-1:q])
        
print(ans)

Submission status: Wrong Answer

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):
    p_, q_ = map(int, input().split())
    p.append(p_)
    q.append(q_)

for i in range(Q):
    ans = 0
    for j in range(M):
        if L[j] < p[i]:
            continue
        elif L[j] > q[i]:
            break
        
        if R[j] <= q[i]:
            ans += 1
    print(ans)

Submission status: Wrong Answer

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

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

c = [[0 for i in range(N)] for j in range(N)]
for i in range(N):
    cnt = 0
    for j in range(N):
        cnt += train[i][j]
        c[i][j] = cnt



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

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
n,m,Q=map(int,input().split())
L=[[0 for i in range(n)] for i in range(n)]
LL=[[0 for i in range(n)] for i in range(n)] 
for i in range(m):
  l,r=map(int,input().split())
  L[l-1][r-1]+=1
LL[0][0]=L[0][0]
for i in range(1,n):
  LL[i][0]=LL[i-1][0]+L[i][0]
  LL[0][i]=LL[0][i-1]+L[0][i]
for i in range(1,n):
  for j in range(1,n):
    LL[i][j]=LL[i-1][j]+LL[i][j-1]+L[i][j]-1
for i in range(Q):
  p,q=map(int,input().split())
  if p==1:
    ans=LL[q-1][q-1]
  elif q==1:
    ans=LL[0][0]
  else:
    ans=LL[q-1][q-1]-LL[q-1][p-2]-LL[p-2][q-1]+LL[p-2][p-2]
  print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n,m,q=map(int,input().split())
L=[[0 for i in range(n)] for i in range(n)]
LL=[[0 for i in range(n)] for i in range(n)] 
for i in range(m):
  l,r=map(int,input().split())
  L[l-1][r-1]+=1
for i in range(n):
  LL[i][0]=L[i][0]
  for j in range(1,n):
    LL[i][j]=LL[i][j-1]+L[i][j]
for i in range(q):
  p,q=map(int,input().split())
  ans=0
  for j in range(p-1,q):
    ans+=LL[j][q-1]-LL[j][p-1]
  print(ans)

Submission status: Wrong Answer

Solution code:
n,m,q = map(int,input().split())
town = [[0 for i in range(n)] for j in range(m)]
for i in range(m):
  l,r = map(int,input().split())
  flag = 1
  for j in range(l,n):
    if j >= r-1:
      flag = 2
    town[i][j] = flag
  if l ==r and l!= 1:
    town[i][l-1] = 2
questions = []
for i in range(q):
  l,r = map(int,input().split())
  count = 0
  for j in range(m):
    if town[j][l-1]==0 and town[j][r-1] ==2:
      count += 1
  print(count)
  #questions.append(list(map(int,input().split())))

#print(town)

Submission status: Wrong Answer

Solution code:
n,m,q = map(int,input().split())
town = [[0 for i in range(n)] for j in range(m)]
for i in range(m):
  l,r = map(int,input().split())
  flag = 1
  for j in range(l,n):
    if j >= r-1:
      flag = 2
    town[i][j] = flag
  if l ==r:
    town[i][l-1] = 2
questions = []
for i in range(q):
  l,r = map(int,input().split())
  count = 0
  for j in range(m):
    if town[j][l-1]==0 and town[j][r-1] ==2:
      count += 1
  print(count)
  #questions.append(list(map(int,input().split())))

#print(town)

Submission status: Wrong Answer

Solution code:
import sys
import bisect
input = sys.stdin.readline

N, M, Q = map(int, input().split())
ML = [list(map(int, input().split())) for _ in range(M)]
QL = [list(map(int, input().split())) for _ in range(Q)]
P = QL.copy()

ML.sort(key = lambda x:x[1])
QL.sort(key = lambda x:x[1])

l = 2
while l < N:
    l *= 2
    
class SegmentTree:
    def __init__(self, le):
        self.le = le
        le = le * 2 - 1
        self.data = [0] * le
    
    def update(self, x, value):
        x += + l - 1
        self.data[x] += value
        
        while x > 0:
            x = (x - 1) // 2
            self.data[x] += value
            
    def get(self, x, y, a, b, index):
        if b < 0:
            b = self.le
            
        if b <= x or y <= a:
            return 0
        
        if x <= a and b <= y:
            return self.data[index]
        
        return self.get(x, y, a, (a + b) // 2, (2 * index) + 1) + self.get(x, y, (a + b) // 2, b, (2 * index) + 2)

tree = SegmentTree(l)

ans = {}
ml_index = 0
for i in range(Q):
    q = QL[i]
    
    for j in range(ml_index, M):
        m = ML[j]
        
        if m[1] > q[1]:
            break
            
        tree.update(m[0] - 1, 1)
            
        ml_index = j + 1

    s = tree.get(q[0] - 1, q[1], 0, -1, 0)
    ans["".join(map(str, q))] = s
    
for p in P:
    print(ans["".join(map(str, p))])

Submission status: Wrong Answer

Solution code:
import numpy as np

Submission status: Wrong Answer

Solution code:
import bisect

N, M, Q = map(int, input().split())
L, R = [], []
for _ in range(M):
    l, r = map(int, input().split())
    L.append(l)
    R.append(r)

L.sort()

for _ in range(Q):
    p, q = map(int, input().split())
    ans = 0
    INDEX_1 = bisect.bisect_left(L, p)
    INDEX_2 = bisect.bisect_right(L, q)
    for i in range(INDEX_1, INDEX_2):
        if R[i] <= q:
            ans += 1
    print(ans)

Submission status: Wrong Answer

Solution code:
N,M,Q=[int(a) for a in input().split(" ")]
LR = [[int(a) for a in input().split(" ")] for i in range(M)]
PQ = [[int(a) for a in input().split(" ")] for i in range(Q)]
LL, RR = [0]*N, [0]*N
for l,r in LR:
    LL[l-1]+=1
    RR[r-1]+=1
for i in range(1,N):
    RR[i]=RR[i]+RR[i-1]
for i in list(range(1,N))[::-1]:
    LL[i-1]=LL[i-1]+LL[i]
for p,q in PQ:
    print((LL[p-1]+RR[q-1]-M))

Submission status: Wrong Answer

Solution code:
import numpy as np


def f():
    nc, nt, nq = map(int, input().split())
    t = [list(map(int, input().split())) for _ in range(nt)]
    q = [list(map(int, input().split())) for _ in range(nq)]
    dp = np.zeros((nc + 1, nc + 1), dtype="i8")
    for l, r in t:
        dp[:l + 1, r:] += 1
    for l, r in q:
        print(dp[l][r])
    print(dp)


f()

Submission status: Wrong Answer

Solution code:
N, M, Q = [int(_) for _ in input().split()]
LR = [[int(_) for _ in input().split()] for _ in range(M)]
PQ = [[int(_) for _ in input().split()] for _ in range(Q)]
cumsum = [[0] * (N + 2) for _ in range(N + 2)]
for l, r in LR:
    cumsum[l][r + 1] += 1
for i in range(1, N + 2):
    for j in range(1, N + 2):
        cumsum[i][j] += cumsum[i][j - 1]
for j in range(1, N + 2):
    for i in range(1, N + 2):
        cumsum[i][j] += cumsum[i - 1][j]
for p, q in PQ:
    print(cumsum[q][q + 1] + cumsum[p - 1][p] - cumsum[p - 1][q + 1])

Submission status: Wrong Answer

Solution code:
N,M,Q=map(int, input().split())
ma=[[0]*(501) for i in range(501)]
inpath=[[int(j) for j in input().split()] for i in range(M)]
inQ=[[int(j) for j in input().split()] for i in range(Q)]

ptr=0
for i in range(1, 501):
    for j in range(1, 501):
        if ptr < M and i == inpath[ptr][0] and j == inpath[ptr][1]:
            cnt = 0
            while ptr < M and i == inpath[ptr][0] and j == inpath[ptr][1]:
                cnt += 1
                ptr += 1
            ma[i][j] = ma[i][j-1] + cnt
            # print("ma[{}][{}]: {}".format(i,j,ma[i][j]))
        else:
            ma[i][j] = ma[i][j-1]
            # print("ma[{}][{}]: {}".format(i,j,ma[i][j]))

for fr, to in inQ:
    cnt = 0
    # print("from: {} to: {}".format(fr, to))
    for j in range(fr, to+1):
        cnt += (ma[j][to] - ma[j][j-1])
    print(cnt)

Submission status: Wrong Answer

Solution code:
N,M,Q=map(int, input().split())
ma=[[0]*(N+1) for i in range(N+1)]
inpath=[[int(j) for j in input().split()] for i in range(M)]
inQ=[[int(j) for j in input().split()] for i in range(Q)]

ptr=0
for i in range(1, N+1):
    for j in range(1, N+1):
        if ptr < M and i == inpath[ptr][0] and j == inpath[ptr][1]:
            cnt = 0
            while ptr < M and i == inpath[ptr][0] and j == inpath[ptr][1]:
                cnt += 1
                ptr += 1
            ma[i][j] = ma[i][j-1] + cnt
            # print("ma[{}][{}]: {}".format(i,j,ma[i][j]))
        else:
            ma[i][j] = ma[i][j-1]
            # print("ma[{}][{}]: {}".format(i,j,ma[i][j]))

for fr, to in inQ:
    cnt = 0
    # print("from: {} to: {}".format(fr, to))
    for j in range(fr, to+1):
        cnt += (ma[j][to] - ma[j][j-1])
    print(cnt)

Submission status: Wrong Answer

Solution code:
N,M,Q=map(int, input().split())
ma=[[0]*(N+1) for i in range(N+1)]
inpath=[[int(j) for j in input().split()] for i in range(M)]
inQ=[[int(j) for j in input().split()] for i in range(Q)]

ptr=0
for i in range(1, N+1):
    for j in range(1, N+1):
        if ptr < M and i == inpath[ptr][0] and j == inpath[ptr][1]:
            cnt = 0
            while ptr < M and i == inpath[ptr][0] and j == inpath[ptr][1]:
                cnt += 1
                # print("ma[{}][{}]: {}".format(i,j,ma[i][j]))
                ptr += 1
            ma[i][j] = ma[i][j-1] + cnt
        else:
            ma[i][j] = ma[i][j-1]

for fr, to in inQ:
    cnt = 0
    # print("from: {} to: {}".format(fr, to))
    for j in range(fr, to+1):
        cnt += (ma[j][to] - ma[j][fr-1])
    print(cnt)

Submission status: Wrong Answer

Solution code:
N,M,Q=map(int, input().split())
ma=[[0]*(N+1) for i in range(N+1)]
inpath=[[int(j) for j in input().split()] for i in range(M)]
inQ=[[int(j) for j in input().split()] for i in range(Q)]

ptr=0
for i in range(1, N+1):
    for j in range(1, N+1):
        if ptr < M and i == inpath[ptr][0] and j == inpath[ptr][1]:
            cnt = 0
            while ptr < M and i == inpath[ptr][0] and j == inpath[ptr][1]:
                cnt += 1
                # print("ma[{}][{}]: {}".format(i,j,ma[i][j]))
                ptr += 1
            ma[i][j] = ma[i][j-1] + cnt
        elif ptr < M:
            ma[i][j] = ma[i][j-1]

for fr, to in inQ:
    cnt = 0
    # print("from: {} to: {}".format(fr, to))
    for j in range(fr, to+1):
        cnt += (ma[j][to] - ma[j][fr-1])
    print(cnt)

Submission status: Wrong Answer

Solution code:
N,M,Q=map(int, input().split())
ma=[[0]*(N+1) for i in range(N+1)]
inpath=[[int(j) for j in input().split()] for i in range(M)]
inQ=[[int(j) for j in input().split()] for i in range(Q)]

ptr=0
for i in range(1, N+1):
    for j in range(1, N+1):
        if ptr < M and i == inpath[ptr][0] and j == inpath[ptr][1]:
            cnt = 0
            while ptr < M and i == inpath[ptr][0] and j == inpath[ptr][1]:
                cnt += 1
                # print("ma[{}][{}]: {}".format(i,j,ma[i][j]))
                ptr += 1
            ma[i][j] = ma[i][j-1] + cnt
        elif ptr < M:
            ma[i][j] = ma[i][j-1]

for fr, to in inQ:
    cnt = 0
    # print("from: {} to: {}".format(fr, to))
    for j in range(fr, to+1):
        cnt += (ma[j][to] - ma[j][j-1])
    print(cnt)