You have an array a1,a2,…,an.
Let's call some subarray al,al+1,…,ar of this array a subpermutation if it contains all
integers from 1 to r−l+1 exactly once. For example, array a=[2,2,1,3,2,3,1] contains 6
subarrays which are subpermutations:[a2…a3],[a2…a4],[a3…a3],[a3…a5],[a5…a7],[a7…
a7].
You are asked to calculate the number of subpermutations.
【Input】
The first line contains one integer n (1≤n≤3⋅105).
The second line contains n integers a1,a2,…,an (1≤ai≤n).
This array can contain the same integers.
【Output】
Print the number of subpermutations of the array a.
Educational Codeforces Round 66 (Rated for Div. 2)-F. The Number of Subpermutations-哈希方法求子排列个数
Educational Codeforces Round 66 (Rated for Div. 2)-F. The Number of Subpermutations-哈希方法求子排列个数【Description】You have an array a1,a2,…,an.Let's call some subarray al,al+1,…,ar of this array a subper...