/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 532.0 KiB
#2 Accepted 1ms 532.0 KiB
#3 Accepted 59ms 532.0 KiB
#4 Accepted 89ms 4.578 MiB
#5 Accepted 87ms 5.523 MiB
#6 Accepted 51ms 532.0 KiB
#7 Accepted 53ms 576.0 KiB
#8 Accepted 52ms 576.0 KiB
#9 Accepted 89ms 5.832 MiB
#10 Accepted 26ms 2.062 MiB

Code

#include <bits/stdc++.h>
using namespace std;

#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);
using ll = long long;

int main() {
  FAST;
  
  int tc = 1, ti;
  cin >> tc;

  for (ti = 1; ti <= tc; ++ti) {
    ll n, i, ans, x, l, cnt;
    cin >> n;

    vector<ll> a(n);
    for (i = 0; i < n; ++i) cin >> a[i];

    map<ll,pair<ll,ll>> mp;
    mp[0] = {0, 1};
    x = 0;
    ans = 0;
    for (i = 0; i < n; ++i) {
      x ^= a[i];
      if (mp.find(x) != mp.end()) {
        tie(l, cnt) = mp[x];
        ans += cnt * i - l;
        mp[x] = {l+i+1, cnt+1};
      } else {
        mp[x] = {i+1, 1};
      }
    }

    cout << ans << "\n";
  }

  return 0;
}

Information

Submit By
Type
Submission
Problem
P1096 Mr. Heart and the XOR Puzzle
Contest
Brain Booster #6
Language
C++17 (G++ 13.2.0)
Submit At
2024-10-03 16:11:04
Judged At
2024-10-03 16:11:04
Judged By
Score
100
Total Time
89ms
Peak Memory
5.832 MiB