107762024-04-12 00:39:5342Telefonközpontpython3Time limit exceeded 40/100575ms17576 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
1Accepted18ms11776 KiB
2Accepted19ms11944 KiB
subtask220/20
3Accepted20ms12104 KiB
4Accepted20ms12308 KiB
5Accepted20ms12672 KiB
6Accepted20ms12792 KiB
7Accepted19ms12696 KiB
8Accepted20ms13008 KiB
9Accepted19ms12924 KiB
subtask320/20
10Accepted20ms12104 KiB
11Accepted20ms12308 KiB
12Accepted20ms12672 KiB
13Accepted20ms12792 KiB
14Accepted19ms12696 KiB
15Accepted20ms13008 KiB
16Accepted19ms12924 KiB
17Accepted57ms14004 KiB
18Accepted59ms14216 KiB
19Accepted52ms14292 KiB
20Accepted52ms14304 KiB
21Accepted52ms14872 KiB
22Accepted52ms14608 KiB
23Accepted54ms14728 KiB
subtask40/60
24Accepted20ms12104 KiB
25Accepted20ms12308 KiB
26Accepted20ms12672 KiB
27Accepted20ms12792 KiB
28Accepted19ms12696 KiB
29Accepted20ms13008 KiB
30Accepted19ms12924 KiB
31Accepted57ms14004 KiB
32Accepted59ms14216 KiB
33Accepted52ms14292 KiB
34Accepted52ms14304 KiB
35Accepted52ms14872 KiB
36Accepted52ms14608 KiB
37Accepted54ms14728 KiB
38Time limit exceeded575ms17388 KiB
39Time limit exceeded556ms17420 KiB
40Time limit exceeded560ms17576 KiB
41Time limit exceeded560ms17420 KiB
42Time limit exceeded524ms17500 KiB
43Time limit exceeded550ms17444 KiB
44Time limit exceeded558ms17460 KiB