fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define ll long long
  5.  
  6. int main()
  7. {
  8. int t,n;
  9. cin >> t;
  10.  
  11. while(t--)
  12. {
  13. cin >> n;
  14. vector<ll> vi(n);
  15.  
  16. int x;
  17. for(int i=0;i<n;i++)
  18. {
  19. cin >> x;
  20. x = abs(x);
  21.  
  22. if(x%2 == 0)
  23. {
  24. if(x%4==0) vi[i] = 2;
  25. else vi[i] = 1;
  26. }
  27. else
  28. {
  29. vi[i] = 0;
  30. }
  31. }
  32.  
  33. //for(auto& s:vi) cout << s << " ";
  34.  
  35. ll l=0,r=0;
  36.  
  37. ll curr=0,ans=0;
  38. bool mrked = false;
  39. // even
  40. while(l<n and r<n)
  41. {
  42. if(l>r)
  43. {
  44. r=l;
  45. mrked = false;
  46. }
  47.  
  48. if(!mrked) curr += vi[r];
  49. // cout << l << " " << r << " " << curr << endl;
  50. if(curr >=2)
  51. {
  52. ans += n-r;
  53. curr -= vi[l];
  54. l++;
  55. mrked = true;
  56. // cout <<" --- " << l << " " << r << " " << curr << endl;
  57.  
  58. }
  59. else
  60. {
  61. mrked = false;
  62. r++;
  63. }
  64. }
  65.  
  66. // cout << ans << endl;
  67. l=0,r=0,curr=0;
  68. while(l<n and r<n)
  69. {
  70.  
  71. while(vi[l])l++;
  72.  
  73. if(l >=n )break;
  74. int x=1;
  75.  
  76. while((l+x < n) and (vi[l+x] == 0)) x++;
  77.  
  78. ans += (x*(x+1))/2;
  79. l += x;
  80.  
  81. }
  82.  
  83. cout << ans << "\n";
  84. }
  85. }
Success #stdin #stdout 0s 4532KB
stdin
1
4 
1 2 3 4
stdout
6