fork(1) download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. int main(){
  4. int n; cin>>n;
  5. int a[n],b[n];
  6. for(int i=0;i<n;i++) cin>>a[i];
  7. for(int i=0;i<n;i++) cin>>b[i];
  8.  
  9. unordered_map<int,int> mp;
  10. mp[0]=-1;
  11.  
  12. int x=0,y=0,ans=0;
  13.  
  14. for(int j=0;j<n;j++){
  15. x^=a[j];
  16. y^=b[j];
  17.  
  18. int z=x^y;
  19.  
  20. if(mp.find(z)!=mp.end()){
  21. int i=mp[z]+1;
  22. ans=max(ans,j-i+1);
  23. }
  24.  
  25. if(mp.find(z)==mp.end())
  26. mp[z]=j;
  27. }
  28.  
  29. cout<<ans;
  30. }
Success #stdin #stdout 0s 5316KB
stdin
3
1 2 3
1 2 3
stdout
3