88792024-02-02 18:34:34NagyLeoLegmesszebbi rossz sorrendű (35 pont)python3Accepted 35/35123ms36692 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 = max_length + i + 1
        if lo > n - 1:
            break
        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()))
n = len(nums)

find_misplaced_elements(nums, n)
SubtaskSumTestVerdictTimeMemory
base35/35
1Accepted0/017ms11252 KiB
2Accepted0/0116ms34636 KiB
3Accepted1/117ms11860 KiB
4Accepted1/117ms11496 KiB
5Accepted1/117ms11932 KiB
6Accepted1/117ms11896 KiB
7Accepted1/117ms12376 KiB
8Accepted1/118ms12608 KiB
9Accepted1/119ms12928 KiB
10Accepted1/120ms13408 KiB
11Accepted1/121ms13556 KiB
12Accepted2/259ms21960 KiB
13Accepted2/264ms23008 KiB
14Accepted2/268ms23576 KiB
15Accepted2/248ms19380 KiB
16Accepted2/268ms24044 KiB
17Accepted2/286ms28296 KiB
18Accepted2/297ms30324 KiB
19Accepted2/2104ms32592 KiB
20Accepted2/2109ms34872 KiB
21Accepted2/2116ms36692 KiB
22Accepted2/2118ms36520 KiB
23Accepted2/2120ms36444 KiB
24Accepted2/2123ms36676 KiB