아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Alternating Algorithm

시간 제한7초메모리 제한1024 MB

요약
주어진 배열에 홀수 라운드와 짝수 라운드가 번갈아 인접 원소를 교환하는 정렬을 적용할 때, 배열이 비감소 순서가 될 때까지 걸리는 라운드 수를 구한다.
난이도

보통10점 중 7점

유형
정렬, 시뮬레이션, 그리디, 구현
정답자
아직 제출이 없습니다

문제

In recent years, CPU manufacturers have found it increasingly difficult to keep up with Moore's law of doubling the number of transistors on integrated circuit chips every two years. To address this, manufacturers have instead started creating CPUs with an increasingly higher number of cores. In fact, you just purchased a CPU with a staggering nn number of cores, no less!

Incidentally, you also have an array of n+1n+1 integers, a_0,a_1,…,a_na\_0, a\_1, \ldots, a\_n, that you need to sort. To make good use of the large number of cores on your CPU, you have devised a parallel sorting algorithm in which there is a dedicated core for comparing each adjacent pair of integers. As long as the array is not sorted in non-decreasing order, the algorithm proceeds in rounds that alternate between:

  • Odd rounds (starting with the first): The first core compares a_0a\_0 and a_1a\_1, the third core compares a_2a\_2 and a_3a\_3, the fifth core compares a_4a\_4 and a_5a\_5, and so on. If a pair of compared elements are out of order, the corresponding core will swap their positions. If nn is even, a_na\_n will be left untouched.
  • Even rounds: The second core compares a_1a\_1 and a_2a\_2, the fourth core compares a_3a\_3 and a_4a\_4, the sixth core compares a_5a\_5 and a_6a\_6, and so on. If a pair of compared elements are out of order, the corresponding core will swap their positions. If nn is odd, a_na\_n will be left untouched, and a_0a\_0 will be left untouched no matter what the parity of nn is.

Note that in both types of rounds some cores may be idle.

Before implementing this algorithm, you have decided to do some analysis. In particular, you noticed that the time complexity of the algorithm does not depend on the value of nn, but rather it depends on the number of rounds that the algorithm runs. Given the initial contents of the array, determine the number of rounds that the parallel sorting algorithm runs before the array becomes sorted.

입력

The input consists of:

  • One line with an integer nn (1≤n≤4⋅1051 \leq n \leq 4\cdot10^5), the number of cores and the size of the array.
  • One line with n+1n+1 integers a_0,a_1,…,a_na\_0, a\_1, \ldots, a\_n (0≤a_i≤1090 \leq a\_i \leq 10^9 for each ii), the initial contents of the array.

출력

Output the number of rounds that the parallel sorting algorithm runs before the array becomes sorted in non-decreasing order.

예제3

  1. 예제 1

    입력
    3
    8 13 4 10
    
    예상 출력
    3
    
  2. 예제 2

    입력
    5
    13 12 14 10 14 12
    
    예상 출력
    3
    
  3. 예제 3

    입력
    2
    2 2 1
    
    예상 출력
    3