题目链接

官网题解写的好清楚,和昨晚Aguin说的一模一样……

这题只和每个数1的个数有关,设每个数1的个数的数组为$b$,就是首先一段如果是好的,要满足两个条件:

1.这一段$b$数组和为偶数,因为奇数总会多出一个1,消不掉。

2.这一段$b$数组中最大的要小于等于这一段总和的一半,因为自己里面的1和自己不能消。

有了这两个条件,先处理第一个条件,做法是枚举左端点,然后统计合法的右端点的个数,就$odd$和$even$数组统计后缀和为奇还是偶,偶-偶,奇-奇就好了,这样能够保证$[l,r]$区间是偶数。

再处理第二个条件,因为每个数$<=10^{18}$,所以最多有60个1,而且每个数不为$0$,所以每个数最少有一个1,那$[l,r]$区间长度大于60后,$b$数组的最大值一定小于等于总和的一半,所以只要把$r$在$[l,l+60]$中,和为偶数最大值大于总和一半的减去就行了。

 #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 3e5 + ;
int b[maxn];
int sum[maxn];
int odd[maxn], even[maxn];
int main()
{
int n; scanf("%d", &n);
for(int i = ; i <= n; i++)
{
ll x;
scanf("%lld", &x);
while(x)
{
if(x % 2LL == 1LL) b[i]++;
x >>= 1LL;
}
//printf("%d\n", b[i]);
}
for(int i = n; i >= ; i--)
{
sum[i] = sum[i + ] + b[i];
odd[i] = odd[i + ], even[i] = even[i + ];
if(sum[i] % == ) even[i]++;
else odd[i]++;
}
ll ans = ;
for(int i = ; i <= n; i++) ///枚举左端点
{
if(sum[i] % == ) ans += even[i + ];
else ans += odd[i + ];
int mx = ;
if(i == ) continue; ///i=0,统计的是右端点为n的区间
for(int j = i; j <= min(n, i + ); j++)
{
mx = max(mx, b[j]);
int tmp = sum[i] - sum[j + ];
if((tmp % == ) && (mx + mx) > tmp) ans--;
}
}
printf("%lld\n", ans);
return ;
}

Codeforces Round #512 (Div. 2, based on Technocup 2019 Elimination Round 1) E. Vasya and Good Sequences的更多相关文章

  1. Codeforces Round #512 (Div. 2, based on Technocup 2019 Elimination Round 1) C. Vasya and Golden Ticket 【。。。】

    任意门:http://codeforces.com/contest/1058/problem/C C. Vasya and Golden Ticket time limit per test 1 se ...

  2. Codeforces Round #512 (Div. 2, based on Technocup 2019 Elimination Round 1) E. Vasya and Good Sequences(DP)

    题目链接:http://codeforces.com/contest/1058/problem/E 题意:给出 n 个数,对于一个选定的区间,区间内的数可以通过重新排列二进制数的位置得到一个新的数,问 ...

  3. Codeforces Round #517 (Div. 2, based on Technocup 2019 Elimination Round 2)

    Codeforces Round #517 (Div. 2, based on Technocup 2019 Elimination Round 2) #include <bits/stdc++ ...

  4. (AB)Codeforces Round #528 (Div. 2, based on Technocup 2019 Elimination Round

    A. Right-Left Cipher time limit per test 1 second memory limit per test 256 megabytes input standard ...

  5. Codeforces Round #517 (Div. 2, based on Technocup 2019 Elimination Round 2) D. Minimum path

    http://codeforces.com/contest/1072/problem/D bfs 走1步的最佳状态 -> 走2步的最佳状态 -> …… #include <bits/ ...

  6. Codeforces Round #517 (Div. 2, based on Technocup 2019 Elimination Round 2) D. Minimum path(字典序)

    https://codeforces.com/contest/1072/problem/D 题意 给你一个n*n充满小写字母的矩阵,你可以更改任意k个格子的字符,然后输出字典序最小的从[1,1]到[n ...

  7. Codeforces Round #528 (Div. 2, based on Technocup 2019 Elimination Round 4) C. Connect Three 【模拟】

    传送门:http://codeforces.com/contest/1087/problem/C C. Connect Three time limit per test 1 second memor ...

  8. Codeforces Round #522 (Div. 2, based on Technocup 2019 Elimination Round 3)B. Personalized Cup

    题意:把一长串字符串 排成矩形形式  使得行最小  同时每行不能相差大于等于两个字符 每行也不能大于20个字符 思路: 因为使得行最小 直接行从小到大枚举即可   每行不能相差大于等于两个字符相当于  ...

  9. Codeforces Round #522 (Div. 2, based on Technocup 2019 Elimination Round 3) C. Playing Piano

    题意:给出一个数列 a1 a2......an  让你构造一个序列(该序列取值(1-5)) 如果a(i+1)>a(i) b(i+1)>b(i) 如果a(i+1)<a(i)  那么b( ...

随机推荐

  1. 3d点云

    rgb-d:rgb加depth组成4channel的 3d点云

  2. Linux平台搭建roboframework

    安装步骤介绍: . 在Centos7..1503下,默认的python的版本2./site-packages/). 2.安装pip 第一步: ()下载setuptools包 # wget http:/ ...

  3. IAP介绍

    iOS应用调置 wjforstudy分享了IAP的一些基本知识.在论坛的地址是:http://www.cocoachina.com/bbs/read.php?tid=92060  1.在开始IAP开发 ...

  4. Python学习笔记2(序列)

    元组不可变序列 tuple函数 总结 字符串 基本字符串的操作 字符串格式化 字符串方法 find join lower replace split strip translate 小结 元组:不可变 ...

  5. 【数学 exgcd】bzoj1407: [Noi2002]Savage

    exgcd解不定方程时候$abs()$不能乱加 Description Input 第1行为一个整数N(1<=N<=15),即野人的数目. 第2行到第N+1每行为三个整数Ci, Pi, L ...

  6. perl中foreach(一)

    perl中的foreach结构  首先语法 foreach $rock(qw /bedrock slate lava/){        $rock="\t$rock";      ...

  7. 序列化 random模块应用

    序列化 我们今天学习下序列化,什么是序列化呢? 将原本的字典.列表等内容转换成一个字符串的过程就叫做序列化. 为什么要有序列化模块: 比如,我们在python代码中计算的一个数据需要给另外一段程序使用 ...

  8. centos 安装 yum apt

    以下地址 http://download.csdn.NET/detail/mimi00x/8081263 执行安装命令 rpm -i rpmforge-release-0.5.3-1.el7.rf.x ...

  9. NYOJ 118 修路方案

    修路方案 时间限制:3000 ms  |  内存限制:65535 KB 难度:5   描述 南将军率领着许多部队,它们分别驻扎在N个不同的城市里,这些城市分别编号1~N,由于交通不太便利,南将军准备修 ...

  10. Leetcode 373.查找和最小的k对数字

    查找和最小的k对数字 给定两个以升序排列的整形数组 nums1 和 nums2, 以及一个整数 k. 定义一对值 (u,v),其中第一个元素来自 nums1,第二个元素来自 nums2. 找到和最小的 ...