1200*D. Same Differences(数学&推公式)

Problem - 1520D - Codeforces

1200*D. Same Differences(数学&推公式)_第1张图片

解析:

        统计 a [ i ] - i  

#include
using namespace std;
#define int long long
const int N=2e5+5;
int t,n,a[N]; 
signed main(){
	scanf("%lld",&t);
	while(t--){
		scanf("%lld",&n);
		mapmp;
		int res=0;
		for(int i=1;i<=n;i++){
			scanf("%lld",&a[i]);
			res+=mp[a[i]-i];
			mp[a[i]-i]++;
		}
		printf("%lld\n",res);
	}
	return 0;
}

 

你可能感兴趣的:(codeforces,算法,c++,c语言,开发语言)