/*
感觉有点不科学,50000的数据量,n^2竟然能过,不可思议。。。
*/
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
const int maxn = 50000 + 5;
const int INF = 0x3f3f3f3f;
int n;
int a[maxn];
int main()
{
//freopen("in.txt", "r", stdin);
scanf("%d", &n);
for(int i = 0; i < n; i++) scanf("%d", &a[i]);
int ans = 0;
for(int l = 0; l < n; l++) {
int minv = INF, maxv = -INF;
for(int r = l; r < n; r++) {
minv = min(minv, a[r]);
maxv = max(maxv, a[r]);
if(maxv - minv == r - l) ans++;
}
}
printf("%d\n", ans);
return 0;
}
连号区间(*)
最新推荐文章于 2022-05-08 16:23:40 发布