CF1322B:Present(异或、two pointers)
生活随笔
收集整理的這篇文章主要介紹了
CF1322B:Present(异或、two pointers)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
解析
想到了按位,但卡在了進位…
qwq
當時總是想一位一位往后轉化,但是那樣確實做不了
判斷第k位時把每個數的前k-1位提出來
sort一下
再維護雙指針,就可以很方便的統計進位的個數了
代碼
#include<bits/stdc++.h> using namespace std; #define ll long long const int N=5e5+100; ll read() {ll x=0,f=1;char c=getchar();while(!isdigit(c)) {if(c=='-')f=-1;c=getchar();}while(isdigit(c)) {x=x*10+(c^48);c=getchar();}return x*f; }int n,m; int mi[25],a[N],b[N]; int ans; int main() { #ifndef ONLINE_JUDGEfreopen("a.in","r",stdin);//freopen("a.out","w",stdout); #endifmi[0]=1;for(int i=1;i<=24;i++) mi[i]=mi[i-1]<<1;n=read();for(int i=1;i<=n;i++) a[i]=read();for(int k=0;k<=24;k++){int tot(0);for(int i=1;i<=n;i++){if(a[i]&mi[k]) tot+=(n-1);b[i]=a[i]&(mi[k]-1);tot&=1;}sort(b+1,b+1+n);//if(k==2){//for(int i=1;i<=n;i++) printf("%d ",b[i]);putchar('\n');//}for(int l=1,r=n+1;l<=n;l++){while(r>1&&b[r-1]+b[l]>=mi[k]) r--;tot+=n-max(r,l+1)+1;tot&=1;//if(k==2) printf("l=%d r=%d tot=%d\n",l,r,tot);}if(tot&1) ans+=mi[k];}printf("%d\n",ans);return 0; } /* 3 501 502 503 */總結
以上是生活随笔為你收集整理的CF1322B:Present(异或、two pointers)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 电脑端微信双开如何实现微信电脑双开
- 下一篇: 如何设置端口映射 端口映射的几种方法