Advertisement
pb_jiang

CF1731C

May 1st, 2025
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.41 KB | None | 0 0
  1. // Problem: C. Even Subarrays
  2. // Contest: Codeforces - Codeforces Round 841 (Div. 2) and Divide by Zero 2022
  3. // URL: https://codeforces.com/problemset/problem/1731/C
  4. // Memory Limit: 256 MB
  5. // Time Limit: 2500 ms
  6. //
  7. // Powered by CP Editor (https://cpeditor.org)
  8.  
  9. #include <assert.h>
  10. #include <bits/stdc++.h>
  11. using namespace std;
  12. #ifndef __DEBUG__
  13. #define dbg(...) 42
  14. #endif
  15. template <class T> using mpq = priority_queue<T, vector<T>, greater<T>>;
  16.  
  17. namespace rngs = std::ranges;
  18. using ll = long long;
  19. using a2l = array<ll, 2>;
  20. using pll = pair<ll, ll>;
  21. using vl = vector<ll>;
  22.  
  23. void solve()
  24. {
  25.     ll n;
  26.     cin >> n;
  27.     vl a(n);
  28.     for (auto &x : a)
  29.         cin >> x;
  30.  
  31.     ll tot = n * (n + 1) / 2, sub = 0;
  32.     vl cnt(2 * n);
  33.     cnt[0] = 1;
  34.  
  35.     for (ll i = 0, sum = 0; i < n; ++i) {
  36.         sum = sum ^ a[i];
  37.         for (ll j = 0; j * j < 2 * n; ++j) {
  38.             ll tg = sum ^ (j * j);
  39.             /*
  40.             // TLE with cnt a map
  41.             if (cnt.count(tg))
  42.                 dbg(tg, sum, j * j, cnt[tg]), sub += cnt[tg];
  43.             */
  44.             if (tg < 2 * n)
  45.                 sub += cnt[tg];
  46.         }
  47.         cnt[sum] += 1;
  48.     }
  49.  
  50.     dbg(tot, sub);
  51.     cout << tot - sub << '\n';
  52. }
  53.  
  54. int main(int argc, char **argv)
  55. {
  56.     std::ios::sync_with_stdio(false);
  57.     std::cin.tie(nullptr);
  58.  
  59.     ll t;
  60.     cin >> t;
  61.     while (t--)
  62.         solve();
  63.  
  64.     return 0;
  65. };
  66.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement