Advertisement
mahfuj02

Untitled

Feb 16th, 2020
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.17 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int main()
  4. {
  5.     int t;
  6.     cin>>t;
  7.     while(t--)
  8.     {
  9.         int n;
  10.         cin>>n;
  11.         int A[n+5],B[n+5],arr[n+5];
  12.         int xa=0,xb=0;
  13.         map<int,int>mp;
  14.         for(int i = 0; i<n; i++)
  15.         {
  16.             cin>>A[i];
  17.             xa^=A[i];
  18.             arr[i]=A[i];
  19.         }
  20.         for(int i = 0;i<n; i++)
  21.         {
  22.             cin>>B[i];
  23.             xb^=B[i];
  24.             mp[B[i] ]++;
  25.         }
  26.  
  27.  
  28.        // cout<<xa<<" "<<xb<<endl;
  29.       /*  if(xa!=xb)
  30.         {
  31.             cout<<-1<<endl;
  32.             continue;
  33.         }*/
  34.         vector<int>v;
  35.         int flag =0;
  36.         for(int i = 0; i<n; i++)
  37.         {
  38.             if(mp[xb^xa^A[i]]>0)
  39.             {
  40.                 mp[xa^xb^A[i] ]--;
  41.                 v.push_back(xb^xa^A[i]);
  42.  
  43.             }
  44.             else
  45.             {
  46.                 flag =1;
  47.                 break;
  48.             }
  49.  
  50.  
  51.         }
  52.  
  53.         if(!flag)
  54.         {
  55.             for(int i = 0; i<n-1; i++)
  56.             {
  57.                 cout<<v[i]<<" ";
  58.             }
  59.             cout<<v[n-1]<<endl;
  60.         }
  61.  
  62.         else cout<<-1<<endl;
  63.  
  64.     }
  65.  
  66.  
  67.  
  68.  
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement