We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
I solved it exactly in same manner as explained in editorial. However, I found the implementation (tester's) quite different (tough) than what was explained. However, I implemented it my way which I feel is relatively easier to understand. In case , anyone feels difficult in understanding the editorial's implementation of O(N) . Please refer the below code:
#include<bits/stdc++.h>usingnamespacestd;#define ll long long intintmain(){// freopen("input.txt","r",stdin);// freopen("output.txt","w",stdout);llt=1;//s(t);while(t--){lln;cin>>n;vector<ll>ar(n+2);for(lli=1;i<=n;i++)cin>>ar[i];vector<ll>pref(n+2);pref[1]=ar[1];for(lli=2;i<=n;i++)pref[i]=ar[i]^pref[i-1];unordered_map<ll,ll>cnt;llsuf=0;llans=0;cnt[0]=1;for(lli=n;i>0;i--){ans+=cnt[pref[i-1]];suf^=ar[i];cnt[suf]++;}cout<<ans<<endl;}}
What Are the Odds?
You are viewing a single comment's thread. Return to all comments →
I solved it exactly in same manner as explained in editorial. However, I found the implementation (tester's) quite different (tough) than what was explained. However, I implemented it my way which I feel is relatively easier to understand. In case , anyone feels difficult in understanding the editorial's implementation of O(N) . Please refer the below code:
Thanks!