0pts,求调
查看原帖
0pts,求调
922644
liumuxian楼主2025/8/3 11:47
#include <bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;
const int N=1e6+10;
int a[N];
signed main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int T;
	cin>>T;
	while(T--){
		int n;
		cin>>n;
		for(int i=1;i<=n;i++) cin>>a[i];
		int l=1,r=0,ans=0,maxn=-1;
		while(l<=n){
			if(a[l]==l){
				l++;
				continue;
			} 
//			cout<<l<<" "<<r<<endl;
			while(r<n&&r<maxn) maxn=max(maxn,a[++r]);
			ans+=(r-l+1);
			l++;
		}
		cout<<ans<<endl;
	}
	return 0;
}
2025/8/3 11:47
加载中...