#P8600. [蓝桥杯 2013 省 B] 连号区间数
[蓝桥杯 2013 省 B] 连号区间数
Problem Description
Xiaoming has been thinking about a strange but interesting problem these days:
In a certain permutation of to , how many consecutive-number intervals are there? The definition of a consecutive-number interval is:
If all elements in the interval (that is, the -th to the -th elements of the permutation), after being sorted in increasing order, form a "consecutive" sequence of length , then this interval is called a consecutive-number interval.
The definition of a "consecutive" sequence is:
For a sequence of length , let its -th element be . If , , then the sequence is considered "consecutive".
When is very small, Xiaoming can quickly compute the answer. But when becomes large, the problem is not so simple. Now Xiaoming needs your help.
Input Format
The first line contains a positive integer , indicating the size of the permutation.
The second line contains distinct numbers , representing a permutation of these numbers.
Output Format
Output an integer, representing the number of different consecutive-number intervals.
4
3 2 4 1
7
5
3 4 2 5 1
9
Hint
In the first sample, there are consecutive-number intervals: , , , , , , .
In the second sample, there are consecutive-number intervals: , , , , , , , , .
Original time limit: 5 seconds, 64 MB. Lanqiao Cup 2013, the 4th Provincial Contest.
Translated by ChatGPT 5