数学等式化简和Map使用
作者:互联网
题目:https://codeforces.com/problemset/problem/1520/D
#include<iostream>
#include<map>
using namespace std;
typedef long long ll;
const int N = 2e5 + 10;
ll a[N];
int main()
{
map<ll, ll>mp;
int T;
cin >> T;
while (T--)
{
ll ans = 0;
memset(a, 0, sizeof(a));
mp.clear();
int n;
cin >> n;
for (int i = 1; i <= n; i++)
{
cin >> a[i];
}
for (int i = 1; i <= n; i++)
{
//count查找与a[i]-i相等的数
if (mp.count(a[i] - i)) { ans += mp[a[i] - i]; }
mp[a[i] - i] += 1;
}
cout << ans << endl;
}
}
标签:化简,Map,int,ll,cin,long,mp,等式,ans 来源: https://blog.csdn.net/qq_52124121/article/details/119062411