107772024-04-12 00:40:2642Telefonközpontpypy3Accepted 100/100453ms120800 KiB
from sys import stdin
input=stdin.readline

class SegmentTree:
    def __init__(self):
        self.tree = None
    def buildTree(self,List):
        n = len(List)
        self.tree = [0 for i in range(2*n)]
        for i in range(n):
            self.tree[i+n] = List[i]
        for i in range(n-1,0,-1):
            self.tree[i] = max(self.tree[i<<1],self.tree[i<<1 | 1])
    def maxInRange(self, left, right):
        n = len(self.tree)//2
        result = 0
        left += n
        right += n
        while left<right:
            if left&1:
                result = max(result, self.tree[left])
                left += 1
            if right&1:
                right -= 1
                result = max(result, self.tree[right])
            left >>= 1
            right >>= 1
        return result

def main():
    M,N,Q = [int(x) for x in input().split()]
    start=[0]*(M+1)
    end=[0]*(M+1)
    for i in range(N):
        A,B = [int(x) for x in input().split()]
        start[A]+=1
        end[B]+=1
    darab=[0]*(M+1)
    cur=0
    for i in range(1,M+1):
        cur+=start[i]
        darab[i]=cur
        cur-=end[i]
    segmentTree = SegmentTree()
    segmentTree.buildTree(darab)
    for i in range(Q):
        A,B = [int(x) for x in input().split()]
        print(segmentTree.maxInRange(A,B+1))
        
main()
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted41ms77232 KiB
2Accepted52ms80540 KiB
subtask220/20
3Accepted57ms86216 KiB
4Accepted54ms86952 KiB
5Accepted61ms86616 KiB
6Accepted61ms87060 KiB
7Accepted61ms87808 KiB
8Accepted56ms87672 KiB
9Accepted52ms87640 KiB
subtask320/20
10Accepted57ms86216 KiB
11Accepted54ms86952 KiB
12Accepted61ms86616 KiB
13Accepted61ms87060 KiB
14Accepted61ms87808 KiB
15Accepted56ms87672 KiB
16Accepted52ms87640 KiB
17Accepted172ms96380 KiB
18Accepted171ms97628 KiB
19Accepted163ms96516 KiB
20Accepted168ms96688 KiB
21Accepted167ms97220 KiB
22Accepted165ms97440 KiB
23Accepted166ms95480 KiB
subtask460/60
24Accepted57ms86216 KiB
25Accepted54ms86952 KiB
26Accepted61ms86616 KiB
27Accepted61ms87060 KiB
28Accepted61ms87808 KiB
29Accepted56ms87672 KiB
30Accepted52ms87640 KiB
31Accepted172ms96380 KiB
32Accepted171ms97628 KiB
33Accepted163ms96516 KiB
34Accepted168ms96688 KiB
35Accepted167ms97220 KiB
36Accepted165ms97440 KiB
37Accepted166ms95480 KiB
38Accepted437ms120420 KiB
39Accepted453ms119612 KiB
40Accepted409ms119588 KiB
41Accepted432ms119296 KiB
42Accepted409ms119640 KiB
43Accepted426ms120676 KiB
44Accepted423ms120800 KiB