标签:can long 输出 const xor lse pre std others
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 132768/132768 K (Java/Others)
Total Submission(s): 4119 Accepted Submission(s): 1796
1 #include<cstdio> 2 #include<cstring> 3 #include<algorithm> 4 #include<vector> 5 #include<queue> 6 #define inf 0x3fffffff 7 #define Memset(x, a) memset(x, a, sizeof(x)) 8 using namespace std; 9 typedef long long LL; 10 const int maxn = 100000 + 5; 11 int tree[32 * maxn][2]; 12 LL val[32 * maxn]; 13 int sz; 14 void init() { 15 memset(tree[0], 0, sizeof(tree[0])); 16 // Memset(tree[0],0); 17 sz = 1; 18 } 19 void add(LL a) { 20 int u = 0; 21 for (int i = 32 ; i >= 0 ; i--) { 22 int b = ((a >> i) & 1) ; 23 if (!tree[u][b]) { 24 memset(tree[sz], 0, sizeof(tree[sz])); 25 // Memset(tree[sz],0); 26 val[sz] = 0; 27 tree[u][b] = sz++; 28 } 29 u = tree[u][b]; 30 } 31 val[u] = a; 32 } 33 LL query(LL a ) { 34 int u = 0; 35 for (int i = 32; i >= 0 ; i--) { 36 int b = ((a >> i) & 1) ; 37 if (tree[u][b ^ 1]) u = tree[u][b ^ 1]; 38 else u = tree[u][b]; 39 } 40 return val[u]; 41 } 42 int main() { 43 int t, n, m, cas = 1; 44 LL a; 45 scanf("%d", &t); 46 while(t--) { 47 init(); 48 scanf("%d%d", &n, &m); 49 for (int i = 0 ; i < n ; i++) { 50 scanf("%lld", &a); 51 add(a); 52 } 53 printf("Case #%d:\n", cas++); 54 for (int i = 0 ; i < m ; i++) { 55 scanf("%d", &a); 56 printf("%lld\n", query(a)); 57 } 58 } 59 return 0; 60 }
标签:can long 输出 const xor lse pre std others
原文地址:https://www.cnblogs.com/qldabiaoge/p/9054066.html