题解 | 谐距下标对

谐距下标对

https://www.nowcoder.com/practice/12fd032361704c978bcb9c2c2b3bb93d

#include <bits/stdc++.h>
#define il inline

using namespace std;
using ll = long long;
using ull = unsigned long long;
using int128=__int128_t;

const ll N = 6e5 + 5, mod = 1e9+7, inf = 1e18;
const double esp=1e-3;
double PI=3.1415926;

il void solve(){
    int n;
    cin>>n;
    vector<int>a(n+1);
    map<int,ll>mp;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        mp[a[i]-i]++;
    }
    ll ans=0;
    for(auto [x,y]:mp){
        ans+=(y-1)*y/2;
    }
    cout<<ans;

}

int main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    
    int t = 1;

    //cin >> t;

    while (t--) {
    
        solve();

    }

    return 0;
}

全部评论

相关推荐

09-29 07:57
已编辑
门头沟学院 Java
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务