fork download
  1. #pragma GCC optimize("Ofast")
  2. #pragma GCC optimize("O2")
  3. #include<bits/stdc++.h>
  4. #define faster ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  5. #define ll long long
  6. using namespace std;
  7. int main()
  8. {
  9. faster
  10. ll n,i,d=0,t=0;
  11. cin>>n;
  12. vector<ll> a(n+1),f(2,0);
  13. for(i=1;i<=n;i++) cin>>a[i];
  14. f[0]=1;
  15. for(i=1;i<=n;i++)
  16. {
  17. t+=a[i];
  18. t%=2;
  19. d+=f[t];
  20. f[t]++;
  21. }
  22. cout<<d;
  23. return 0;
  24. }
Success #stdin #stdout 0s 5284KB
stdin
6
1 2 3 4 5 6
stdout
9