What Are the Odds?

Sort by

recency

|

24 Discussions

|

  • + 0 comments

    How this problem is solved by Binary Search ? Please Anyone. Thanks !

  • + 0 comments

    Please can anybody explain how cnt[x] can be computed in O(n)? Thanks

  • + 1 comment

    What are the constraints here?i am a newbie in competitive programming......I mean what are the rules of the games.i found the explanation a little unclear.Please help

  • + 4 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:

    #include<bits/stdc++.h>
    using namespace std;
    
    #define ll long long int
    
    int main()
    {
    	// freopen("input.txt","r",stdin);
     	// freopen("output.txt","w",stdout);
    	ll t=1;
    	//s(t);
    	while(t--){
    		ll n;
    		cin>>n;
    		vector<ll>ar(n+2);
    		for(ll i=1;i<=n;i++)cin>>ar[i];
    
    		vector<ll>pref(n+2);
    		pref[1]=ar[1];
    		for(ll i=2;i<=n;i++)pref[i]=ar[i]^pref[i-1];
    
    		unordered_map<ll,ll> cnt;
    
    		ll suf=0;
    		ll ans=0;
    		cnt[0]=1;
    		for(ll i=n;i>0;i--){
    			ans+=cnt[pref[i-1]];
    			suf^=ar[i];
    			cnt[suf]++;
    		}
    		cout<<ans<<endl;
    
    	}
    }
    

    Thanks!

  • + 2 comments

    If I unlock the editorial on this challenge, will it affect my overall score for the whole contest? I don't want to lose my points from my other solution.