Uva 12571 - Brother & Sisters!
// Accepted
// Just care about the repeated Numbers.You can do store memories for them
#include<cstdio>
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#define sf scanf
#define pf printf
using namespace std;
typedef long long LL;
typedef set<LL>sll;
typedef map<LL,bool>mpbll;
LL ar[100100], ans[100100];
int main()
{
mpbll mp;
int t;
cin >> t;
while(t--)
{
mp.clear();
LL n,q,i,j,mx;
cin >> n >> q;
for(i=0;i<n;i++)
{
cin >> ar[i];
}
for(i=0;i<q;i++)
{
LL x;
cin >> x;
if(!mp[x])
{
//cout << x << " ";
LL mx = -1;
for(j=0;j<n;j++)
{
mx = max(mx, ar[j] & x);
}
ans[x] = mx;
cout << mx << "\n";
mp[x] = true;
}
else
{
cout << ans[x] << "\n";
}
}
}
return 0;
}
// Just care about the repeated Numbers.You can do store memories for them
#include<cstdio>
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#define sf scanf
#define pf printf
using namespace std;
typedef long long LL;
typedef set<LL>sll;
typedef map<LL,bool>mpbll;
LL ar[100100], ans[100100];
int main()
{
mpbll mp;
int t;
cin >> t;
while(t--)
{
mp.clear();
LL n,q,i,j,mx;
cin >> n >> q;
for(i=0;i<n;i++)
{
cin >> ar[i];
}
for(i=0;i<q;i++)
{
LL x;
cin >> x;
if(!mp[x])
{
//cout << x << " ";
LL mx = -1;
for(j=0;j<n;j++)
{
mx = max(mx, ar[j] & x);
}
ans[x] = mx;
cout << mx << "\n";
mp[x] = true;
}
else
{
cout << ans[x] << "\n";
}
}
}
return 0;
}
Comments
Post a Comment