/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 324.0 KiB
#2 Accepted 1ms 320.0 KiB
#3 Accepted 65ms 692.0 KiB
#4 Accepted 111ms 4.594 MiB
#5 Accepted 116ms 5.645 MiB
#6 Accepted 57ms 532.0 KiB
#7 Accepted 58ms 572.0 KiB
#8 Accepted 59ms 568.0 KiB
#9 Accepted 107ms 5.859 MiB
#10 Accepted 24ms 2.066 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-12-17 11:35:17
Judged By
Score
100
Total Time
116ms
Peak Memory
5.859 MiB