/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 2ms 324.0 KiB
#2 Accepted 1ms 344.0 KiB
#3 Accepted 63ms 732.0 KiB
#4 Accepted 56ms 4.57 MiB
#5 Accepted 61ms 6.051 MiB
#6 Accepted 60ms 580.0 KiB
#7 Accepted 58ms 576.0 KiB
#8 Accepted 58ms 576.0 KiB
#9 Accepted 60ms 6.305 MiB
#10 Accepted 35ms 1.316 MiB

Code

//                 بِسْمِ ٱللَّٰهِ ٱلرَّحْمَٰنِ ٱلرَّحِيمِ
//                اللَّهُمَّ إِنِّي أَسْأَلُكَ عِلْمًا نَافِعًا وَرِزْقًا طَيِّبًا وَعَمَلاً مُتَقَبَّلاً 



#include<bits/stdc++.h>
#define ll                  long long
#define pb                  push_back
#define ppb                 pop_back
#define checkmate           return 0
#define yes                 cout<<"YES"<<endl
#define no                  cout<<"NO"<<endl
#define gcd(a,b)            __gcd(a,b)
#define lcm(a,b)            (a*b)/gcd(a,b)
#define for1(i , y)         for(ll i = y ; i<n ; i++) 
#define for2(i , y)         for(ll i = y ; i<m ; i++) 
#define vi(n)               vector<int> v(n)
#define vll                 vector<ll>
#define vcin(v)             for(ll i = 0; i<n ; i++) cin>>v[i] 
#define MOD                 1000000007
#define f                   first
#define s                   second
#define all(v)              v.begin(),v.end() 
#define allr(v)             v.rbegin(),v.rend()          
#define setpr               cout<<fixed<<setprecision(1)<< x <<endl
#define vmax                *max_element(v.begin(),v.end())
#define vmin                *min_element(v.begin(),v.end())
#define fast()              ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl                '\n'
#define dbg(...)
//             T   B   L   R    TL  TR   BL  BR
int dx[10] = {-1 , 1 , 0 , 0 , -1 , -1 , 1 , 1};
int dy[10] = { 0 , 0 ,-1 , 1 , -1 ,  1 ,-1 , 1};
//            -------------    ----------------
//              side move       diagonal move
const int N = 1e5 + 7;
int a[1000+5];
using namespace std;

void file(){
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
}

double wasted(pair<double,double>p1 , pair<double,double> p2)
{
    return sqrtl((p1.f-p2.f)*(p1.f-p2.f)+(p1.s-p2.s)*(p1.s-p2.s));
}

bool isBalanced(char c1 , char c2){
   return (c1 == '(' && c2 == ')' || c1 == '[' && c2 == ']');
}

bool isVowel(char c){
    return (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u');
}

bool isPrime(int n) {
    if (n <= 1) return false;
    if (n <= 3) return true;
    if (n % 2 == 0 || n % 3 == 0) return false;
    for (int i = 5; i * i <= n; i += 6) {
        if (n % i == 0 || n % (i + 2) == 0) return false;
    }
    return true;

}
ll sum(ll n){
    ll ans = 0;
    while(n){
        ans += n % 10;
        n /= 10;
    }
    return ans;
}


//----------------   Solution Here   ----------------/

void solve(){
      int n; cin >> n; 
        vector<int> v(n);
        for (int i = 0; i < n; i++) {
            cin >> v[i];  
        }
        ll px = 0;
        ll ans = 0;
        unordered_map<ll, ll> xc;
        unordered_map<ll, ll> xs;
        xc[0] = 1;
        xs[0] = 0;
        
        for (int i = 0; i < n; i++) {
            px ^= v[i];  
            if (xc.find(px) != xc.end()) { 
                ans += xc[px] * i - xs[px];
            }
            xc[px]++;
            xs[px] += (i + 1);
        }
        
        cout << ans << endl;
}

int main()
{
     fast();
    //file();
    ll t ; cin>>t;
    //int tt=1;
    while(t--) 
    {
      //cout<<"Case "<<tt<<": ";
     // tt++;
     solve();
    }
    //solve();
   checkmate;
}

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:23:37
Judged At
2024-11-11 02:48:32
Judged By
Score
100
Total Time
63ms
Peak Memory
6.305 MiB