题目 1456: [历届试题]连号区间数
Time limit: 1Sec Memory Limit: 128MB
Title Description
Xiao Ming has been thinking about this strange and interesting question these days: How many consecutive number intervals are there in a certain full permutation of 1 to N? The definition of a contiguous interval here is: If all the elements in the interval [L, R] (i.e., the Lth to the Rth elements of the arrangement) are sorted incrementally to obtain a “consecutive” series of length R-L+1, then the interval is called a consecutive interval. When N is small, Xiao Ming can quickly figure out the answer, but when N becomes large, the problem is not so simple, and now Xiao Ming needs your help.
input
The first row is a positive integer N (1 < = N < = 50000), representing the size of the full permutation. The second line is N different numbers Pi (1 < = Pi < = N), representing some full permutation of these N numbers.
Output
Output an integer indicating the number of different concatenated intervals.
Sample Input
|
|
Sample Output
|
|
C Code
|
|