zoukankan      html  css  js  c++  java
  • Tjoi 2017 异或和

    题链

     SOL: 我们可以搞事情。按位枚。

       对每一位统计有几对前缀和之差在此位上为1.

       讨论一下就出来了。

       

    #include<bits/stdc++.h>
    #define LL long long
    #define N 200007
    #define M (N<<1)
    using namespace std;
    int siz,n,x,s[N],nb,lat;
    long long ret,res;
    struct Tree{
        LL ta[2*M];
        inline void c(int x,LL t){x+=1;for(;x<=siz+1;x+=x&(-x)){ta[x]+=t;}}
        inline LL q(int x){x+=1;static LL r;for(r=0;x;x-=x&(-x)){r+=ta[x];}return r;}
        inline LL s(int l,int r){return q(r)-q(l);}
        inline void clear(){for(int i=0;i<=siz+1;i++){ta[i]=0;}}
    }T[2];
    signed main () {
        scanf("%d",&n); for (int i=1;i<=n;i++) scanf("%d",&x),s[i]=s[i-1]+x;
        for (int k=0;(1<<k)<=s[n];k++) {
            siz=(1<<k)-1; ret=0;
            for (int i=0;i<=n;i++) {
                nb=(s[i]>>k)&1; lat=siz&s[i];
                ret+=T[1^nb].s(-1,lat)+T[nb].s(lat,siz); T[nb].c(lat,1);
            } res=res+(1<<k)*(ret&1); T[0].clear(); T[1].clear();
        }
        printf("%lld
    ",res);
    }
  • 相关阅读:
    1276
    1235
    1170
    Grids
    1137
    1127
    1076
    🍖Mysql三种模式的指定方式介绍
    🍖存储引擎介绍
    🍖MySQL库的详细操作
  • 原文地址:https://www.cnblogs.com/rrsb/p/8671776.html
Copyright © 2011-2022 走看看