88782024-02-02 18:33:52NagyLeoLegmesszebbi rossz sorrendű (35 pont)pypy3Runtime error 6/3587ms101236 KiB
def find_misplaced_elements(nums, n):
    max_length = 0
    first_num = 0
    second_num = 0
    minimums = [0] * n
    # minimums[-i] megmondja a leghatso i minimumat
    minimums[-1] = nums[-1]
    for i in range(n - 2, -1, -1):
        minimums[i] = min(minimums[i + 1], nums[i])
    for i in range(n - 1):
        # if minimums[i+1] >= nums[i]:
        #    continue
        if minimums[-1] < nums[i]:
            if n - 1 - i > max_length:
                max_length = n - 1 - i
                first_num = i
                second_num = n - 1
                continue
        lo = min(max_length + i + 1, n - 1)
        hi = n - 1
        if minimums[lo] >= nums[i]:
            continue
        while hi - lo > 1:
            mid = (lo + hi) // 2
            if minimums[mid] < nums[i]:
                lo = mid
            else:
                hi = mid
        max_length = lo - i
        first_num = i
        second_num = lo

    if max_length > 0:
        print(first_num + 1, second_num + 1)
    else:
        print(-1)


n = int(input())
nums = list(map(int, input().split()))

find_misplaced_elements(nums, n)
SubtaskSumTestVerdictTimeMemory
base6/35
1Accepted0/052ms87460 KiB
2Runtime error0/079ms98016 KiB
3Accepted1/150ms87864 KiB
4Accepted1/154ms87636 KiB
5Accepted1/148ms87648 KiB
6Accepted1/146ms87208 KiB
7Wrong answer0/146ms87396 KiB
8Wrong answer0/150ms89448 KiB
9Wrong answer0/157ms95056 KiB
10Wrong answer0/159ms95556 KiB
11Wrong answer0/159ms95712 KiB
12Wrong answer0/271ms99800 KiB
13Wrong answer0/272ms100652 KiB
14Accepted2/274ms101112 KiB
15Wrong answer0/279ms98516 KiB
16Wrong answer0/287ms101236 KiB
17Runtime error0/274ms97572 KiB
18Runtime error0/270ms97132 KiB
19Runtime error0/279ms95732 KiB
20Runtime error0/270ms95372 KiB
21Runtime error0/268ms95352 KiB
22Runtime error0/270ms95336 KiB
23Runtime error0/268ms94956 KiB
24Runtime error0/268ms95120 KiB