CF1174D Ehab and the Expected XOR Problem(二进制)

做法

求出答案序列的异或前缀和\(sum_i\)\([l,r]\)子段异或和可表示为\(sum_r\bigoplus sum_{l-1}\)

故转换问题为,填\(sum\)数组,数组内的元素不为\(0\)且互不相同,且两两异或不为\(x\)

预处理\(x\)为多对值,每对值异或起来为\(x\),显然是两两互不影响的,每对值选择任意一个填就行了

最后还得从\(sum_i=\bigoplus_{j=1}^i a_i\)转换为\(a_i\)

code

#include<bits/stdc++.h>
using namespace std;
typedef int LL;
const LL maxn=2e6+9;
inline LL Read(){
    LL x(0),f(1); char c=getchar();
    while(c<'0' || c>'9'){
        if(c=='-') f=-1; c=getchar();
    }
    while(c>='0' && c<='9'){
        x=(x<<3)+(x<<1)+c-'0'; c=getchar();
    }return x*f;
}
LL n,x,tot,sum;
LL to[maxn],visit[maxn],ans[maxn];
vector<LL> e;
int main(){
    n=Read(); x=Read();
    LL up(1<<n);
    e.push_back(0);
    visit[x]=1;
    for(LL i=1;i<up;++i){
        if(visit[i]) continue;
        visit[x^i]=1;
        e.push_back(i);
    }
    printf("%d\n",e.size()-1);
    for(LL i=1;i<e.size();++i) printf("%d ",e[i]^e[i-1]);
    return 0;
}

转载于:https://www.cnblogs.com/y2823774827y/p/10973546.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值