88792024-02-02 18:34:34NagyLeoLegmesszebbi rossz sorrendű (35 pont)python3Elfogadva 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)
RészfeladatÖsszpontTesztVerdiktIdőMemória
base35/35
1Elfogadva0/017ms11252 KiB
2Elfogadva0/0116ms34636 KiB
3Elfogadva1/117ms11860 KiB
4Elfogadva1/117ms11496 KiB
5Elfogadva1/117ms11932 KiB
6Elfogadva1/117ms11896 KiB
7Elfogadva1/117ms12376 KiB
8Elfogadva1/118ms12608 KiB
9Elfogadva1/119ms12928 KiB
10Elfogadva1/120ms13408 KiB
11Elfogadva1/121ms13556 KiB
12Elfogadva2/259ms21960 KiB
13Elfogadva2/264ms23008 KiB
14Elfogadva2/268ms23576 KiB
15Elfogadva2/248ms19380 KiB
16Elfogadva2/268ms24044 KiB
17Elfogadva2/286ms28296 KiB
18Elfogadva2/297ms30324 KiB
19Elfogadva2/2104ms32592 KiB
20Elfogadva2/2109ms34872 KiB
21Elfogadva2/2116ms36692 KiB
22Elfogadva2/2118ms36520 KiB
23Elfogadva2/2120ms36444 KiB
24Elfogadva2/2123ms36676 KiB