zoukankan      html  css  js  c++  java
  • CF1614C Divan and bitwise operations

    题目

    分析

    (比赛时直接看出来结论就过了)

    直接抛结论:所有子集的异或和的和等于 所有数的或 \(\times 2^{n-1}\)

    首先可以得到这样一个柿子(其中 \(s\) 是当前位在数组中值为 \(1\) 的个数):

    \[\large \sum_{i=0}^{\log V}2^i\times 2^{n-s}\sum^{\lfloor\frac{s-1}{2}\rfloor}_{j=0}\dbinom s{2j+1}=\sum_{i=0}^{\log V}2^i\times [s>0]2^{n-1} \]

    然后把最后那个东西提出来,前面那一堆求和其实就是所有数的或的和。

    所以答案就是 所有数的或 \(\times 2^{n-1}\)

    代码

    #include<bits/stdc++.h>
    using namespace std;
    //#ifdef ONLINE_JUDGE
    //	#define getchar() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
    //	char buf[1<<21],*p1=buf,*p2=buf;
    //#endif
    template<typename T>
    inline void read(T &x){
    	x=0;bool f=false;char ch=getchar();
    	while(!isdigit(ch)){f|=ch=='-';ch=getchar();}
    	while(isdigit(ch)){x=x*10+(ch^48);ch=getchar();}
    	x=f?-x:x;
    	return ;
    }
    template<typename T>
    inline void write(T x){
    	if(x<0) x=-x,putchar('-');
    	if(x>9) write(x/10);
    	putchar(x%10^48);
    	return ;
    }
    #define ll long long
    #define ull unsigned long long
    #define ld long double
    #define pb push_back
    #define mp make_pair
    #define fi first
    #define se second
    #define pc putchar
    #define PII pair<int,int>
    #define rep(i,x,y) for(register int i=(x);i<=(y);i++)
    #define dep(i,y,x) for(register int i=(y);i>=(x);i--)
    #define repg(i,x) for(int i=head[x];i;i=nex[i])
    #define filp(s) freopen(s".in","r",stdin),freopen(s".out","w",stdout)
    #define infilp(s) freopen(s".in","r",stdin)
    #define outfilp(s) freopen(s".out","w",stdout)
    const int MOD=1e9+7;
    inline int inc(int x,int y){x+=y;return x>=MOD?x-MOD:x;}
    inline int dec(int x,int y){x-=y;return x<0?x+MOD:x;}
    inline void incc(int &x,int y){x+=y;if(x>=MOD) x-=MOD;}
    inline void decc(int &x,int y){x-=y;if(x<0) x+=MOD;}
    inline void chkmin(int &x,int y){if(y<x) x=y;}
    inline void chkmax(int &x,int y){if(y>x) x=y;}
    const int N=2e5+5,M=2e5+5,INF=1e9+7;
    int n,m,a[N];
    char str[N];
    inline ll QuickPow(ll x,ll y){
    	ll res=1;
    	while(y){
    		if(y&1) res=res*x%MOD;
    		x=x*x%MOD;
    		y>>=1;
    	}
    	return res;
    }
    signed main(){
    //	double ST=clock();
    	// ios::sync_with_stdio(false);
    //#ifndef ONLINE_JUDGE
    //	filp("my");
    //#endif
    	int T;read(T);
    	while(T--){
    		ll sum=0;
    		read(n),read(m);int l,r;
    		rep(i,1,m) read(l),read(r),read(a[i]),sum|=a[i];
    		write(QuickPow(2,n-1)*sum%MOD),pc('\n');
    	}
    //	cerr<<"\nTime:"<<(clock()-ST)/CLOCKS_PER_SEC<<"s\n";
    	return 0;
    }
    /*
    
    */
    
    
    
     
    
  • 相关阅读:
    (基础) --- KMP字符串
    (基础)--- 前缀和、差分
    PHOTOSHOP --- 分辨率、图片保存格式
    Oracle Delete数据后手动释放空间
    掌握爬虫技术需要学哪些内容?
    如何用python制作动态二维码,来哄女朋友开心?
    python为什么会环境变量设置不成功
    python和js交互调用的方法
    基于PHP实现解密或加密Cloudflar邮箱保护
    基于pytorch中的Sequential用法说明
  • 原文地址:https://www.cnblogs.com/Akmaey/p/15619435.html
Copyright © 2011-2022 走看看