301683: CF319B. Psychos in a Line

Memory Limit:256 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Psychos in a Line

题意翻译

有N个精神病患者排成一行。每个精神病患者被分配一个从1到N的唯一整数。在每一回合中,每一个拥有比他右边邻居更大值的精神病人都会杀死他右边的邻居(如果他有邻居的话)。注意,一个精神病患者可能会在杀死邻居的同一回合被杀死。 你得到了心理医生的初步安排。计算出在这样的情况下需要多少回合之后才会没有人杀死他的邻居。

题目描述

There are $ n $ psychos standing in a line. Each psycho is assigned a unique integer from $ 1 $ to $ n $ . At each step every psycho who has an id greater than the psycho to his right (if exists) kills his right neighbor in the line. Note that a psycho might kill and get killed at the same step. You're given the initial arrangement of the psychos in the line. Calculate how many steps are needed to the moment of time such, that nobody kills his neighbor after that moment. Look notes to understand the statement more precise.

输入输出格式

输入格式


The first line of input contains integer $ n $ denoting the number of psychos, $ (1<=n<=10^{5}) $ . In the second line there will be a list of $ n $ space separated distinct integers each in range $ 1 $ to $ n $ , inclusive — ids of the psychos in the line from left to right.

输出格式


Print the number of steps, so that the line remains the same afterward.

输入输出样例

输入样例 #1

10
10 9 7 8 6 5 3 4 2 1

输出样例 #1

2

输入样例 #2

6
1 2 3 4 5 6

输出样例 #2

0

说明

In the first sample line of the psychos transforms as follows: \[10 9 7 8 6 5 3 4 2 1\] $ → $ \[10 8 4\] $ → $ \[10\]. So, there are two steps.

Input

题意翻译

有N个精神病患者排成一行。每个精神病患者被分配一个从1到N的唯一整数。在每一回合中,每一个拥有比他右边邻居更大值的精神病人都会杀死他右边的邻居(如果他有邻居的话)。注意,一个精神病患者可能会在杀死邻居的同一回合被杀死。 你得到了心理医生的初步安排。计算出在这样的情况下需要多少回合之后才会没有人杀死他的邻居。

加入题单

算法标签: