Xiao Ming these days have been thinking about such a strange and interesting question:
How many even numbers in the range of 1 to do a full array of N? Here's the definition of even number range is:
If the interval [L, R] in all elements (i.e., in this arrangement the L-th to the R elements) after ascending order to get a length of "continuous" series R-L + 1, and called this interval even number range.
When N was very young, Xiao Ming can quickly calculate the answer, but when N becomes large when the problem is not so simple, and now Bob needs your help.
The first line is a positive integer N (1 <= N <= 50000), represents the size of the whole arrangement.
The second line is the N different number Pi (1 <= Pi <= N), which represents a certain N digital full array.
Output an integer representing the number of different sections even numbers.
3 2 4 1
3 4 2 5 1
#include <bits/stdc++.h> using namespace std; int n; long long ans=0; int fa[50005]; int a[50005]; int main() { cin>>n; int i,j; for(i=1;i<=n;i++) { scanf("%d",&a[i]); } for(i=1;i<=n;i++) { int mmax=0,mmin=99999; for(j=i;j<=n;j++) { mmax=max(mmax,a[j]); mmin=min(mmin,a[j]); if(j-i==mmax-mmin)ans++; } } cout << years; return 0 ; }