fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main() {
  5. int n;
  6. cin >> n;
  7. vector<int> array(n, 0);
  8. for (int i = 0; i < n; i++)
  9. cin >> array[i];
  10. long long answer = 0;
  11. map<vector<int>, long long> mp;
  12. mp[{0, 0, 0, 0}] = 1;
  13. int c1 = 0, c2 = 0, c3 = 0, c4 = 0, c5 = 0;
  14. for (int j = 0; j < n; j++) {
  15. if (array[j] == 1)
  16. c1++;
  17. else if (array[j] == 2)
  18. c2++;
  19. else if (array[j] == 3)
  20. c3++;
  21. else if (array[j] == 4)
  22. c4++;
  23. else if (array[j] == 5)
  24. c5++;
  25.  
  26. vector<int> diff = {c2 - c1, c3 - c2, c4 - c3, c5 - c4};
  27. if(mp.find(diff)!=mp.end())
  28. answer += mp[diff];
  29. mp[diff]++;
  30. }
  31. cout << answer;
  32. return 0;
  33. }
Success #stdin #stdout 0s 544KB
stdin
10
1 2 3 4 5 1 2 3 4 5
stdout
7