fork download
  1. #include <bits/stdc++.h>
  2. #include <ext/pb_ds/assoc_container.hpp>
  3. #include <ext/pb_ds/tree_policy.hpp>
  4. #define all(st) st.begin(), st.end()
  5. #define el '\n'
  6. #define sp ' '
  7. #define ld long double
  8. #define fixed(x) fixed << setprecision(x)
  9. #define BI acos(-1)
  10. #define nl '\n'
  11. using ll = long long;
  12. using namespace __gnu_pbds;
  13. using namespace std;
  14. template <class t>
  15. using ordered_set = tree<t, null_type, less<t>, rb_tree_tag, tree_order_statistics_node_update>;
  16. template <class t>
  17. using ordered_multiset = tree<t, null_type, less_equal<t>, rb_tree_tag, tree_order_statistics_node_update>;
  18. int main(void)
  19. {
  20. ios_base::sync_with_stdio(false);
  21. cin.tie(NULL);
  22.  
  23. int n; cin >> n;
  24. vector<ll> arr(n);
  25. for(int i = 0;i < n; i++)
  26. {
  27. cin >> arr[i];
  28. }
  29.  
  30. vector<ll> suffreq(n+1,0);
  31. ll evencnt = 0 , oddcnt =0;
  32. for(int i = 1; i <= n; i++)
  33. {
  34. suffreq[i] = suffreq[i-1];
  35. if(arr[i-1] == 1) suffreq[i]++;
  36. if(suffreq[i]%2 == 0)
  37. {
  38. evencnt++;
  39. }
  40. else
  41. {
  42. oddcnt++;
  43.  
  44. }
  45.  
  46.  
  47. }
  48. cout << oddcnt*(evencnt+1);
  49.  
  50.  
  51. }
Success #stdin #stdout 0.01s 5328KB
stdin
Standard input is empty
stdout
Standard output is empty