fork download
  1. #include <bits/stdc++.h>
  2. #define endl '\n'
  3. #define ll long long
  4. #define fl float
  5. using namespace std;
  6. #include <ext/pb_ds/assoc_container.hpp>
  7. #include <ext/pb_ds/tree_policy.hpp>
  8. using namespace __gnu_pbds;
  9. template <typename T>
  10. using pbds = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
  11. void solve()
  12. {
  13. int n;
  14. cin >> n;
  15. vector<int> a(n);
  16. for (int i = 0; i < n; i++)
  17. {
  18. cin >> a[i];
  19. }
  20. int ans = 0;
  21. for (int i = 0; i < n; i++)
  22. {
  23. for (int j = i; j < n; j++)
  24. {
  25. double avg_petal = 0;
  26. for(int k = i ;k <= j ;k++) avg_petal+= a[k];
  27. avg_petal/= (j-i+1);
  28.  
  29. for(int k = i;k<=j;k++){
  30. if(a[k] == avg_petal){
  31. ans++;
  32. break;
  33. }
  34. }
  35. }
  36. }
  37. cout<<ans<<endl;
  38. }
  39. int32_t main()
  40. {
  41. ios::sync_with_stdio(false);
  42. cin.tie(NULL);
  43. ll t = 1;
  44. // cin >> t;
  45. while (t--)
  46. {
  47. solve();
  48. }
  49. return 0;
  50. }
Success #stdin #stdout 0.01s 5292KB
stdin
4
1 1 2 3
stdout
6