zoukankan      html  css  js  c++  java
  • CF1322B Present

    题目

    分析

    好像是经典套路,但是我还是不会。

    区间异或和并不好直接维护,于是想到按位处理。

    枚举二进制的每一位,然后直接对于原序列所有数模一个 \(2^{k+1}\) (假设枚举的是 \(k\)

    然后对当前位有影响的就是和在区间 \([2^k,2^{k+1}-1]\) 和区间 \([2^k+2^{k+1},2\times (2^{k+1}-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=4e5+5,M=2e5+5,INF=1e9+7;
    int n,m,a[N],b[N],Ans;
    signed main(){
    //	double ST=clock();
    	// ios::sync_with_stdio(false);
    //#ifndef ONLINE_JUDGE
    //	filp("my");
    //#endif
    	read(n);
    	for(int i=1;i<=n;i++) read(a[i]);
    	for(int k=0;k<=28;k++){
    		const int now=(1<<k);
    		int res=0;
    //		cout<<k<<":";
    		for(int i=1;i<=n;i++) b[i]=a[i]&((now<<1)-1);
    //		cout<<endl;
    		sort(b+1,b+n+1);
    		for(int i=1;i<=n;i++){
    			int pos1=lower_bound(b+1,b+n+1,now-b[i])-b,
    				pos2=upper_bound(b+1,b+n+1,(now<<1)-1-b[i])-b,
    				pos3=lower_bound(b+1,b+n+1,(now<<1)+now-b[i])-b;
    //			pos2--;
    			res+=(n-pos1+1)-(n-pos2+1)+(n-pos3+1);
    			if(pos1<=i) res--;
    			if(pos2<=i) res++;
    			if(pos3<=i) res--;
    		}
    		res/=2;
    //		cout<<k<<":"<<res<<endl;
    		if(res&1) Ans+=now;
    	}
    	write(Ans);
    //	cerr<<"\nTime:"<<(clock()-ST)/CLOCKS_PER_SEC<<"s\n";
    	return 0;
    }
    /*
    
    */
    
  • 相关阅读:
    Django重新构造User模型
    在docker中添加mysql在通过远程机器的访问
    php基础笔记
    mysql基础笔记整理
    redis的配置安装与使用
    c++实现对两个有序链表的连接
    java的网络编程(TCP)
    无心制作
    nacos配置服务
    声明式远程调用OpenFeign(微服务调用微服务)
  • 原文地址:https://www.cnblogs.com/Akmaey/p/15617932.html
Copyright © 2011-2022 走看看