首页 > 其他 > 详细

Codeforces 1053 B - Vasya and Good Sequences

时间:2020-01-29 17:05:40      阅读:82      评论:0      收藏:0      [点我收藏+]

题:

思路:

满足异或值为0的区间,必须满足一下条件:

1.区间中二进制1的个数和为偶数个;

2.区间二进制1的个数最大值的两倍不超过区间和.

技术分享图片
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
typedef long long ll;
const int M=1e6+5;
ll a[10],countt[M];
int main(){
    ll ans=0;
    int n;
    scanf("%d",&n);
    int sign=0;
    a[0]=1;
    for(int i=1;i<=n;i++){
        ll x;
        scanf("%I64d",&x);
        int t=0;
        while(x){
            if(x&1)
                t++;
            x>>=1;
        }
        countt[i]=countt[i-1]+t;
        sign^=t&1;
        ans+=a[sign];
        ll maxx=0;
        for(int j=i;i-j<=64&&j>=1;j--){
            maxx=max(maxx,countt[j]-countt[j-1]);
            if((countt[i]-countt[j-1])%2==0&&2*maxx>countt[i]-countt[j-1])
                ans--;
        }
        a[sign]++;
    }
    printf("%I64d",ans);
    return 0;
}
View Code

 

Codeforces 1053 B - Vasya and Good Sequences

原文:https://www.cnblogs.com/starve/p/12240489.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!