#P10833. Counting Permutation Subarrays
Counting Permutation Subarrays
Counting Permutation Subarrays
Given a sequence (a) of length (N), count the number of pairs ((l, r)) such that (1 \le l \le r \le N) and the subarray (a_l, a_{l+1}, \ldots, a_r) is a permutation of (1, 2, \ldots, r-l+1).
In other words, the subarray (a_l, a_{l+1}, \cdots, a_r) should contain all integers from (1) to (r-l+1) exactly once.
inputFormat
The input consists of two lines. The first line contains the integer (N) (the length of the sequence). The second line contains (N) space-separated integers representing the sequence (a).
outputFormat
Output a single integer representing the number of valid pairs ((l, r)).
sample
3
1 2 3
3