88802024-02-02 18:40:16NagyLeoLegmesszebbi rossz sorrendű (35 pont)python3Accepted 35/35123ms37228 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 = tuple(map(int, input().split()))
n = len(nums)

find_misplaced_elements(nums, n)
SubtaskSumTestVerdictTimeMemory
base35/35
1Accepted0/018ms11284 KiB
2Accepted0/0120ms35108 KiB
3Accepted1/117ms11940 KiB
4Accepted1/117ms11956 KiB
5Accepted1/117ms12344 KiB
6Accepted1/117ms12376 KiB
7Accepted1/117ms12628 KiB
8Accepted1/117ms12808 KiB
9Accepted1/120ms13104 KiB
10Accepted1/120ms13384 KiB
11Accepted1/121ms13836 KiB
12Accepted2/261ms22336 KiB
13Accepted2/264ms23604 KiB
14Accepted2/267ms24996 KiB
15Accepted2/248ms19872 KiB
16Accepted2/271ms25512 KiB
17Accepted2/287ms29324 KiB
18Accepted2/297ms32644 KiB
19Accepted2/2105ms33200 KiB
20Accepted2/2107ms34304 KiB
21Accepted2/2115ms37036 KiB
22Accepted2/2115ms37220 KiB
23Accepted2/2123ms36980 KiB
24Accepted2/2122ms37228 KiB