找子数组的个数
双指针
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=2e5+10;
int a[N];
void solve(){
int n;
cin>>n;
for(int i=1;i<=n;i++)cin>>a[i];
int l=1,r=1;
int ans=0;
while(l<=r){
if(l>n||r>n)break;
while(a[r]<r-l+1)l++;
ans+=r-l+1;
r++;
}
cout<<ans<<"\n";
}
signed main(){
ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
int t=1;
cin>>t;
for(int i=1;i<=t;i++)solve();
return 0;
}
标签:Good,int,Subarrays,long,Version,Easy,C1
From: https://www.cnblogs.com/yufan1102/p/18014453