码迷,mamicode.com
首页 > 其他好文 > 详细

cf842d Vitya and Strange Lesson

时间:2018-02-11 22:44:57      阅读:207      评论:0      收藏:0      [点我收藏+]

标签:oid   scan   else   scanf   sso   print   dep   names   blog   

#include <iostream>
#include <cstdio>
using namespace std;
int s[2000005][2], cnt, n, m, x, uu, ans, dep[2000005], siz[2000005];
void ins(){
    int u=0;
    for(int i=19; i>=0; i--){
        int t=(x&(1<<i))>0;
        if(!s[u][t])    s[u][t] = ++cnt;
        u = s[u][t];
    }
}
void dfs(int o){
    if(o)   siz[o] = 1;
    if(s[o][0]) dfs(s[o][0]);
    if(s[o][1]) dfs(s[o][1]);
    siz[o] += siz[s[o][0]] + siz[s[o][1]];
}
void getAns(){
    int u=0;
    for(int i=19; i>=0; i--){
        int t=(x&(1<<i))>0;
        if(siz[s[u][t]]!=(1<<(i+1))-1){
            ans |= t<<i;
            u = s[u][t];
        }
        else{
            ans |= (t^1)<<i;
            u = s[u][t^1];
        }
    } 
}
int main(){
    cin>>n>>m;
    for(int i=1; i<=n; i++){
        scanf("%d", &x);
        ins();
    }
    x = 0;
    dfs(0);
    while(m--){
        ans = 0;
        scanf("%d", &uu);
        x ^= uu;
        getAns();
        printf("%d\n", ans^x);
    }
    return 0;
}

cf842d Vitya and Strange Lesson

标签:oid   scan   else   scanf   sso   print   dep   names   blog   

原文地址:https://www.cnblogs.com/poorpool/p/8443224.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!