import java.util.ArrayList;
import java.util.Scanner;
public class ContinuousInterval {
private static int N,paixu[],min=Integer.MAX_VALUE,max=Integer.MIN_VALUE,time;
public static void main(String[] args) {
// TODO 自动生成的方法存根
Scanner read=new Scanner(System.in);
N=read.nextInt();
paixu=new int[N];
read.nextLine();
String str=read.nextLine();
String strr[]=str.split(" ");
for(int i=0;i<strr.length;i++){
paixu[i]=Integer.valueOf(strr[i]);
}
for(int i=0;i<paixu.length;i++){
for(int j=i;j<paixu.length;j++){
if(min>paixu[j]){
min=paixu[j];
}
if(max<paixu[j]){
max=paixu[j];
}
if(min==max||max-min+1==j-i+1){
time++;
}
}
min=Integer.MAX_VALUE;
max=Integer.MIN_VALUE;
}
read.close();
System.out.println(time);
}
}
连号区间数
最新推荐文章于 2024-11-15 14:22:33 发布