AcWing 1210. 连号区间数
原题链接
简单
作者:
wjie
,
2020-07-28 13:20:58
,
所有人可见
,
阅读 418
#include <iostream>
#include <cstdio>
using namespace std;
const int N = 1e4 + 5;
int arr[N];
int main()
{
int n;
scanf("%d", &n);
for (int i = 1; i <= n; ++i) scanf("%d", &arr[i]);
int res = n;
for (int l = 1; l <= n-1; ++l)
{
int maxv = arr[l], minv = arr[l];
for (int len = 2; l + len - 1 <= n; ++len)
{
int j = l + len - 1;
if (arr[j] > maxv) maxv = arr[j];
else if (arr[j] < minv) minv = arr[j];
if (maxv - minv + 1 == len) res++;
}
}
printf("%d", res);
return 0;
}