-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path12571_Brother_Sisters.cpp
More file actions
66 lines (48 loc) · 1.25 KB
/
12571_Brother_Sisters.cpp
File metadata and controls
66 lines (48 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include <bits/stdc++.h>
#define ALL(x) x.begin(), x.end()
#define FAST std::cin.tie(0); ios::sync_with_stdio(false); std::cout.tie(0);
using namespace std;
#define min(a,b) (a < b) ? (a) : (b)
#define max(a,b) (a > b) ? (a) : (b)
#define vii vector<pair<int,int>>
#define ii pair<int, int>
#define ll long long
#define TC int t; cin >> t; while (t--)
void solve() {
cout << "Hi";
}
int ands[230][256];
#define M (1 << 8) - 1 //
int main(int argc, char const *argv[])
{
for (int i= 0; i < 230; i++) {
for (int j = 0; j < 256; j++) {
ands[i][j] = i & j;
}
}
int n, q, a;
int ans = 0;
TC {
cin >> n >> q;
int x[n];
int cache[230];
for (int i = 0; i < 230; i++) cache[i] = 512; // any number that won't appear.
for (int i = 0; i < n; i++) {
cin >> x[i];
}
for (; q--;) {
ans = 0;
cin >> a;
if (cache[a] != 512) {
ans = cache[a];
}
else {
for (int i = 0; i < n; i++)
ans = max(ans, ands[a][x[i]&M]);
cache[a] = ans;
}
cout << ans << endl;
}
}
return 0;
}