http://codeforces.com/contest/842/problem/D
树 二进制(路径,每个节点代表一位)
1 #include <cstdio> 2 #include <cstdlib> 3 #include <cmath> 4 #include <cstring> 5 #include <time.h> 6 #include <string> 7 #include <set> 8 #include <map> 9 #include <list> 10 #include <stack> 11 #include <queue> 12 #include <vector> 13 #include <bitset> 14 #include <ext/rope> 15 #include <algorithm> 16 #include <iostream> 17 using namespace std; 18 #define ll long long 19 #define minv 1e-6 20 #define inf 1e9 21 #define pi 3.1415926536 22 #define E 2.7182818284 23 const ll mod=1e9+7;//998244353 24 const int maxn=1e5+10; 25 26 bool tr[524288<<2]={0};//19+2 27 int f[21]; 28 int w=19; 29 30 int main() 31 { 32 int n,m,a,b,i,j,k,value; 33 scanf("%d%d",&n,&m); 34 while (n--) 35 { 36 scanf("%d",&a); 37 b=a; 38 for (i=w;i>=1;i--) 39 { 40 41 f[i]=a & 1; 42 a>>=1; 43 } 44 j=1; 45 for (i=1;i<=w;i++) 46 { 47 j<<=1; 48 if (f[i]==1) 49 j++; 50 } 51 tr[j]=1; 52 } 53 54 for (i=(1<<w)-1;i>=1;i--) 55 tr[i]=tr[i<<1]&tr[i<<1|1]; 56 57 b=0; 58 while (m--) 59 { 60 scanf("%d",&a); 61 b=a^b; 62 63 a=b; 64 for (i=w;i>=1;i--) 65 { 66 f[i]=a & 1; 67 a>>=1; 68 } 69 j=1; 70 k=1<<(w-1); 71 value=0; 72 for (i=1;i<=w;i++) 73 { 74 j<<=1; 75 if (!tr[j+f[i]]) 76 { 77 j+=f[i]; 78 } 79 else 80 { 81 j+=(f[i] ^ 1); 82 value+=k; 83 } 84 k>>=1; 85 } 86 printf("%d\n",value); 87 } 88 return 0; 89 }