ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

Educational Codeforces Round 134 D

2022-09-06 19:00:09  阅读:195  来源: 互联网

标签:map Educational const int Codeforces long ++ 134 define


D. Maximum AND

可以很轻松通过^和& 两个操作看出 我们要求的两个序列每一位上的1加起来必须等于n才行
多一个少一个都不行
然后1加起来等于n 0自然加起来也等于n 0和1的数量相等
但是直接每一位算肯定是不对的 因为会有有些组不同 比如样例1
我们考虑按位贪心 让后面的组要是和前面组符合 那么加入即可
这里就可以用map 要是后面的组符合前面的组 那么我们就算加上了1<<j也依然符合才行

#include <bits/stdc++.h>
using namespace std;
const int N = 1e5+10;
const int M = 998244353;
const int mod = 1000000007;
#define int long long
#define endl '\n'
#define Endl '\n'
#define YES cout<<"YES"<<endl;
#define NO cout<<"NO"<<endl;
#define _ 0
#define inf 0x3f3f3f3f3f3f3f3f
#define fast ios::sync_with_stdio(false);cin.tie(nullptr);

void solve() {
    int n;
    cin >> n;
    vector<int> a(n), b(n);
    for (int i = 0; i < n; i++)cin >> a[i];
    for (int i = 0; i < n; i++)cin >> b[i];
    int c = 0;
    for (int j = 29; j >= 0; j--) {
        map<int, int> mp;
        c += 1 << j;
        for (int i = 0; i < n; i++) {
            mp[a[i] & c]++;
            mp[~b[i] & c]--;
        }
        bool flag = true;
        for (auto i: mp) {
            if (i.second != 0) {
                flag = false;
                break;
            }
        }
        if (!flag) c -= (1 << j);
    }
    cout << c << endl;
}
signed main(){
    fast
    int T;cin>>T;
    while(T--) {
        solve();
    }
    return ~~(0^_^0);
}

标签:map,Educational,const,int,Codeforces,long,++,134,define
来源: https://www.cnblogs.com/ycllz/p/16662983.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有