fork download
  1. /******************************************************************************
  2.  
  3. Welcome to GDB Online.
  4. GDB online is an online compiler and debugger tool for C, C++, Python, Java, PHP, Ruby, Perl,
  5. C#, OCaml, VB, Swift, Pascal, Fortran, Haskell, Objective-C, Assembly, HTML, CSS, JS, SQLite, Prolog.
  6. Code, Compile, Run and Debug online from anywhere in world.
  7.  
  8. *******************************************************************************/
  9. #include <bits/stdc++.h>
  10. using namespace std;
  11.  
  12. int main()
  13. {
  14. int k=5;
  15. vector<int>a={5, 6, 7, 8, 9};
  16. int n=a.size();
  17. map<int,int>mp;
  18. mp[0]=1;
  19. int sum=0;
  20. //vector<int>p(n,0);
  21. int count=0;
  22. for(int i=0;i<n;i++){
  23. sum=sum^a[i];
  24. if(mp.find(sum^k)!=mp.end()){
  25. count+=mp[sum^k];
  26. }
  27. mp[sum]++;
  28. }
  29.  
  30. cout<<count<<endl;
  31.  
  32. return 0;
  33. }
Success #stdin #stdout 0s 5316KB
stdin
Standard input is empty
stdout
2