tuki2501

So24_Bai4.cpp

Nov 1st, 2021
1,071
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.35 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main() {
  5.   cin.tie(0)->sync_with_stdio(0);
  6.   int n; cin >> n;
  7.   vector<int> a(n + 1);
  8.   for (int i = 1; i <= n; i++) {
  9.     cin >> a[i];
  10.   }
  11.   int ans = 0;
  12.   unordered_map<int,int> mem;
  13.   for (int i = 1; i <= n; i++) {
  14.     ans += mem[i - a[i]];
  15.     mem[a[i] + i]++;
  16.   }
  17.   cout << ans << '\n';
  18. }
Advertisement
Add Comment
Please, Sign In to add comment