fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define int long long int
  4. #define double long double
  5. #define print(a) for(auto x : a) cout << x << " "; cout << endl
  6.  
  7.  
  8. const int M = 1000000007;
  9. const int N = 3e5+9;
  10. const int INF = 2e9+1;
  11. const int LINF = 2000000000000000001;
  12.  
  13. inline int power(int a, int b, int mod=M) {
  14. int x = 1;
  15. a %= mod;
  16. while (b) {
  17. if (b & 1) x = (x * a) % mod;
  18. a = (a * a) % mod;
  19. b >>= 1;
  20. }
  21. return x;
  22. }
  23.  
  24.  
  25. //_ ***************************** START Below *******************************
  26.  
  27.  
  28.  
  29.  
  30. vector<int> a;
  31.  
  32. int consistency(int n){
  33.  
  34. int sum = 0;
  35. int xr = 0;
  36.  
  37. int ans = 0;
  38.  
  39. int s = 0, e = 0;
  40. while(e<n){
  41. sum += a[e];
  42. xr ^= a[e];
  43.  
  44. if(sum == xr){
  45. ans += e-s+1;
  46. e++;
  47. }
  48. else{
  49. while(s<=e && sum != xr){
  50. sum -= a[s];
  51. xr ^= a[s];
  52. s++;
  53. }
  54. if(sum == xr){
  55. ans += e-s+1;
  56. }
  57. e++;
  58. }
  59. }
  60. return ans;
  61.  
  62. }
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
  74.  
  75.  
  76.  
  77.  
  78. int practice(int n){
  79.  
  80. int ans = 0;
  81.  
  82. int s = 0, e = 0;
  83. int sum = 0;
  84. int xr = 0;
  85.  
  86. while(e<n){
  87. sum += a[e];
  88. xr ^= a[e];
  89.  
  90. if(sum == xr){
  91. ans += e-s+1;
  92. e++;
  93. }
  94. else{
  95. while(s<=e && sum != xr){
  96. sum -= a[s];
  97. xr ^= a[s];
  98. s++;
  99. }
  100. if(sum == xr){
  101. ans += e-s+1;
  102. }
  103. e++;
  104. }
  105.  
  106. }
  107.  
  108. return ans;
  109. }
  110.  
  111.  
  112.  
  113.  
  114.  
  115. void solve() {
  116.  
  117. int n;
  118. cin>> n;
  119.  
  120. a.resize(n);
  121. for(int i=0; i<n; i++) cin >> a[i];
  122.  
  123. // cout << consistency(n) << endl;
  124.  
  125. cout << consistency(n) << " " << practice(n) << endl;
  126.  
  127.  
  128. }
  129.  
  130.  
  131.  
  132.  
  133.  
  134. int32_t main() {
  135. ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  136.  
  137. int t = 1;
  138. cin >> t;
  139. while (t--) {
  140. solve();
  141. }
  142.  
  143. return 0;
  144. }
Success #stdin #stdout 0s 5300KB
stdin
2
4
2 5 4 6
5
1 2 3 4 5
stdout
5 5
7 7