fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main() {
  5.  
  6. int n,k;
  7. cin>>n>>k;
  8.  
  9. vector<int> numbers(n);
  10.  
  11. for(auto& number: numbers){
  12. cin>>number;
  13. }
  14.  
  15. int largest = INT_MIN, smallest = INT_MAX;
  16.  
  17. unordered_map<int,int> firstOccurrence, lastOccurrence;
  18.  
  19. int xorSum = 0;
  20.  
  21. firstOccurrence[0] = -1, lastOccurrence[0] = -1;
  22.  
  23. for(int i=0; i<n; i++){
  24. xorSum ^= numbers[i];
  25.  
  26. if(firstOccurrence.find(xorSum^k) != firstOccurrence.end()){
  27. largest = max(largest, i - firstOccurrence[xorSum^k]);
  28. smallest = min(smallest, i - lastOccurrence[xorSum^k]);
  29. }
  30.  
  31. if(firstOccurrence.find(xorSum) == firstOccurrence.end())firstOccurrence[xorSum] = i;
  32.  
  33. lastOccurrence[xorSum] = i;
  34. }
  35.  
  36. cout<<largest<<" "<<smallest<<endl;
  37.  
  38. return 0;
  39. }
Success #stdin #stdout 0s 5308KB
stdin
5 6 
4 2 2 6 4
stdout
5 1