• Codeforces Round #430 (Div. 2) D. Vitya and Strange Lesson


    因为抑或,一眼字典树
    但是处理起来比较难

    #include<iostream>
    #include<map>
    #include<iostream>
    #include<cstring>
    #include<cstdio>
    #include<set>
    #include<vector>
    #include<queue>
    #include<stack>
    #include<cmath>
    #include<algorithm>
    using namespace std;
    typedef long long ll;
    const int N = 6e6+5;
    #define MS(x,y) memset(x,y,sizeof(x))
    #define MP(x, y) make_pair(x, y)
    const int INF = 0x3f3f3f3f;
    
    int nx[N][2];
    int cnt[N];
    int has[N];
    int tot;
    void insert(int x) {
        int rt = 0;
        for(int i = 18; i >= 0; --i) {
            int tt = (x>>i) & 1;
        //  printf("%d
    ", rt);
            if(!nx[rt][tt]) {
                nx[rt][tt] = ++tot;
            }
            rt = nx[rt][tt];
            cnt[rt] ++;
        }
    //  has[rt] = 1;
    }
    void search(int x) {
        int rt = 0;
        int ans = 0;
        for(int i = 18; i >= 0; --i) {
            int tt = (x >> i) & 1;
            if( (1<<i) - cnt[nx[rt][0 ^ tt]] ) {
                if(cnt[nx[rt][0 ^ tt]] == 0) break;
                rt = nx[rt][0 ^ tt];
            }else {
                if(cnt[nx[rt][1 ^ tt]] == 0) {
                //  printf("hh
    ");
                    ans += 1<<i;
                    break;
                }
    
                rt = nx[rt][1 ^ tt]; ans += 1<<i;
            }
        //  printf("%d %d
    ", rt, 0^tt);
        }
        printf("%d
    ", ans);
    }
    int main() {
        int n, m;
        while(~scanf("%d %d", &n, &m)) {
            MS(nx, 0);
            MS(cnt, 0);
            tot = 0;
            map<int, int> mp;
            for(int i = 1; i <= n; ++i) {
                int a; scanf("%d", &a); 
                if(mp.find(a) == mp.end()) insert(a);
                mp[a] ++;
            }
            int tmp = 0;
            for(int i = 0; i < m; ++i) {
                int a; scanf("%d", &a);
                tmp ^= a;
                search(tmp);
            }
        }
        return 0;
    }
  • 相关阅读:
    mybatis的缓存机制
    mybatis动态SQL
    mybatis关联集合List&分布查询传递多列值
    winrt获取文件MD5码
    在wpf中使用winrt的Toast弹框效果
    winrt控件
    WdatePicker组件不显示
    Thread.Sleep in WinRT
    google 语音api
    UTF8编码转换(C#)
  • 原文地址:https://www.cnblogs.com/Basasuya/p/8433687.html
Copyright © 2020-2023  润新知