Notes to sample tests:
Magical subarrays are shown with pairs of indices [a;b] of the beginning and the end.
In the first sample: [1;1], [2;2], [3;3], [4;4], [2;3].
In the second sample: [1;1], [2;2], [3;3], [4;4], [5;5], [1;2], [2;3], [1;3].
代码:
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <vector>
#include <queue>
#include <cstdio>
#include <cmath>
#include <string>
#include <stack>
#include <cctype>
using namespace std;
__int64 a[1000005];
int main()
{
__int64 n;
while(~scanf("%I64d",&n))
{
a[0]=10000000004;
__int64 kk=0;
__int64 sum=0;
for(__int64 i=1; i<=n; i++)
{
scanf("%I64d",&a[i]);
if(a[i]==a[i-1])
kk++;
if(a[i]!=a[i-1])
{
kk++;
sum+=kk*(kk-1)/2;
kk=0;
}
}
if(a[n]==a[n-1])
{
kk++;
sum+=kk*(kk-1)/2;
}
printf("%I64d\n",n+sum);
}
return 0;
}