4502: G. Let Them Eat Cake

内存限制:1024 MB 时间限制:1 S 标准输入输出
题目类型:传统 评测方式:Special Judge 上传者:
提交:0 通过:0

题目描述

Let them eat cake. King Bobo said while looking down at the n poor people begging on their knees inside the majestic palace. What makes King Bobo different from Marie Antoinette is that King Bobo truly did offer them cakes.
King Bobo lets the n people stand in a line, with the i-th (1<= i<= n) people from the left having a label ai. All labels are integers from 1 to n and pairwise distinct. King Bobo then offers the cakes in rounds, by the following rule:
  • When only one person is in the line, King Bobo gives him/her a cake, and the process ends.
  • Otherwise, King Bobo offers a cake to all people whose label is smaller than some of his/her adjacent people (Each person may have 1 or 2 adjacent people, for those with 2 adjacent people, having a label smaller than either of the two can grant him/her a cake). Those who received the cake leave the line, and the remaining ones close the gaps and maintain the same order in the line. This counts as a round.
King Bobo wants to know how many rounds will be counted until the process ends. A king will never do the counting by himself, so it becomes your work.

输入格式

The first line contains an integer n (1<= n<= 105), denoting the number of poor people.
The next line contains n integers a1,a2,...,an (1<= ai<= n,ai is pairwise distinct ) , denoting the label of each person in the line from left to right.

输出格式

Output an integer in a line, denoting the answer.

输入样例 复制

5
1 2 3 4 5

输出样例 复制

1

数据范围与提示

For the first sample test, in the first round, people with labels 1,2,3,4 receive a cake and leaves the line, leaving the line with only one person. So the process ends in one round.
For the second sample test, in the first round, people with labels 1,2,3 receive a cake and leaves the line; in the second round, the person with label 4 receives a cake and leaves the line. So the process ends in two rounds.
input
5
1 5 3 4 2
output
2
input
2
1 2
output
1

分类标签