fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main() {
  5. ios::sync_with_stdio(false);
  6. cin.tie(nullptr);
  7.  
  8. int t;
  9. cin >> t;
  10.  
  11. while (t--) {
  12. int n;
  13. cin >> n;
  14.  
  15. vector<int> a(n);
  16. for (int i = 0; i < n; i++) cin >> a[i];
  17.  
  18. auto check = [&](int i, int v) {
  19. if (i >= 0) return v == a[i] + a[i + 2] - a[i + 4];
  20. return false;
  21. };
  22.  
  23. unordered_map<int, int> cnt;
  24. long long ans = 0;
  25.  
  26. for (int i = 0; i < n - 4; i++) {
  27. int v = a[i] + a[i + 2] - a[i + 4];
  28. int c = cnt[v];
  29. int oc = check(i - 2, v) + check(i - 4, v);
  30. ans += c - oc;
  31. cnt[v] = c + 1;
  32. }
  33.  
  34. cout << ans << '\n';
  35. }
  36. }
  37.  
Success #stdin #stdout 0s 5320KB
stdin
Standard input is empty
stdout
Standard output is empty