Subarray Sort
시간 제한1초메모리 제한1024 MB
1부터 N까지의 순열이 주어질 때, 길이 L인 구간을 정렬하는 데 floor(sqrt(L))초가 걸린다면 전체를 정렬하는 최소 시간을 구한다.
문제
After spending winter break at his grandpa’s, Little Square returned home. While he was away, his friend, Little Triangle, played with his toys, numbered from to . In order for Little Square not to be upset with him, Little Triangle has to put his toys back in order: .
Initially, all the toys are lined up on a shelf in some order.
Knowing that Little Triangle can sort a continuous interval of toys in seconds, help him find the minimum time he can order all the toys.
제한
- denotes the greatest integer .
- Each number between and will appear exactly once in .
- The grader given to the contestants is not necessarily the same with the grader used for scoring.
힌트
In the first example, Little Triangle can sort the interval in second. The permutation becomes . He can now sort the interval in second. The permutation becomes . In total Little Triangle can sort all the toys in seconds, which is also the minimum possible time.
In the second example, the toys are already sorted.