fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define FAST_IO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  4. #define endl '\n'
  5. void fac(long long no,long long p)
  6. {
  7. long long sum = no*(no+1)/2;
  8. cout << sum - p << endl;
  9. }
  10.  
  11.  
  12. int main() {
  13. FAST_IO;
  14. long long t;
  15. cin >> t;
  16. while(t--)
  17. {
  18. long long n;
  19. cin >> n;
  20. long long arr[n];
  21. for(int i=0;i<n;i++)
  22. {
  23. long long p;
  24. cin >> p;
  25. if(p < 0)
  26. arr[i] = -p;
  27. else
  28. arr[i] = p;
  29. }
  30. long long count = 0;
  31. for(long long i=0;i<n;i++)
  32. {
  33. if(arr[i] % 4 == 2)
  34. {
  35. count += 1;
  36. for(long long j = i+1;j<n;j++)
  37. {
  38. if(arr[j] %2 != 0)
  39. count += 1;
  40. else
  41. break;
  42. }
  43. }
  44. else if(arr[i] %2 != 0)
  45. {
  46. int flag = 0;
  47. for(long long j=i+1;j<n;j++)
  48. {
  49. if(flag == 0)
  50. {
  51. if(arr[j] == 0)
  52. break;
  53. else if(arr[j]%4 == 2)
  54. {
  55. count += 1;
  56. flag = 1;
  57. }
  58. }
  59. if(flag == 1)
  60. {
  61. if(arr[j]%2 != 0)
  62. count += 1;
  63. else
  64. break;
  65. }
  66. }
  67. }
  68. }
  69. fac(n,count);
  70. }
  71. return 0;
  72. }
Success #stdin #stdout 0s 4460KB
stdin
Standard input is empty
stdout
3