[题目链接]

https://codeforces.com/contest/1058/problem/E

[算法]

显然 , 我们只需考虑序列中每个数的二进制表示下1的个数即可。 不妨令Ai表示第i个数的二进制表示下1的个数。

一个子序列[L,R]是“好”的当且仅当 :

1. sigma{ Ai }  (L <= i <= R) 为偶数

2. max{ Ai } (L <= i <= R) <= sigma{ Ai } / 2

枚举序列左端点L , 可以用后缀和处理R

时间复杂度 :O(N)

[代码]

#include<bits/stdc++.h>
using namespace std;
const int MAXN = 3e5 + ; int n;
int cnt[MAXN][];
int a[MAXN];
long long ans; template <typename T> inline void read(T &x)
{
T f = ; x = ;
char c = getchar();
for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
for (; isdigit(c); c = getchar()) x = (x << ) + (x << ) + c - '';
x *= f;
} int main()
{ read(n);
for (int i = ; i <= n; i++)
{
long long x;
read(x);
while (x > )
{
a[i] += x & ;
x >>= ;
}
}
int suf = ;
cnt[n + ][] = ;
for (int i = n; i >= ; i--)
{
int sum = , mx = ;
int add = ;
for (int j = i; j <= n && j - i < ; j++)
{
sum += a[j];
mx = max(mx,a[j]);
if (sum % == && mx > sum - mx) add--;
}
suf += a[i];
add += cnt[i + ][suf & ];
ans += add;
cnt[i][] = cnt[i + ][];
cnt[i][] = cnt[i + ][];
if (suf & ) cnt[i][]++;
else cnt[i][]++;
} printf("%I64d\n",ans); return ; }

[Codeforces 1058E] Vasya and Good Sequences的更多相关文章

  1. [Codeforces 1053B] Vasya and Good Sequences

    Link: Codeforces 1053B 传送门 Solution: 其实就是暴力 观察需要满足的条件: 1.个数和为偶数 2.最大个数不大于其它所有个数的和 如果只有第一个条件记录前缀和的奇偶性 ...

  2. 2018.09.23 codeforces 1053B. Vasya and Good Sequences(前缀和)

    传送门 考试的时候卡了一会儿. 显然这个答案只跟二进制位为1的数量有关. 还有一个显然的结论. 对于一个区间[l,r][l,r][l,r],如果其中单个数二进制位为1的数量最大值不到区间所有数二进制位 ...

  3. Codeforces 1053 B - Vasya and Good Sequences

    B - Vasya and Good Sequences 思路: 满足异或值为0的区间,必须满足一下条件: 1.区间中二进制1的个数和为偶数个; 2.区间二进制1的个数最大值的两倍不超过区间和. 如果 ...

  4. codeforces 1041 E.Vasya and Good Sequences(暴力?)

    E. Vasya and Good Sequences time limit per test 2 seconds memory limit per test 256 megabytes input ...

  5. [CF1030E]Vasya and Good Sequences

    [CF1030E]Vasya and Good Sequences 题目大意: 给定一个长度为\(n(n\le3\times10^5)\)的数列\(a_i(1\le a_i\le10^{18})\). ...

  6. CodeForces - 837E - Vasya's Function | Educational Codeforces Round 26

    /* CodeForces - 837E - Vasya's Function [ 数论 ] | Educational Codeforces Round 26 题意: f(a, 0) = 0; f( ...

  7. 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 个数,对于一个选定的区间,区间内的数可以通过重新排列二进制数的位置得到一个新的数,问 ...

  8. Codeforces Round #512 E - Vasya and Good Sequences

    有时候觉得自己就是个思路搬运机,只会搬运思路 这个题首先说了求的是好区间的个数,  好区间满足条件: 1.二进制位1的数量和为偶数    2.w[i]表示a[i]的二进制上1的个数 ,sum[i] = ...

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

    题目链接 官网题解写的好清楚,和昨晚Aguin说的一模一样…… 这题只和每个数1的个数有关,设每个数1的个数的数组为$b$,就是首先一段如果是好的,要满足两个条件: 1.这一段$b$数组和为偶数,因为 ...

随机推荐

  1. phpstorm破解激活码

    一.将“0.0.0.0 account.jetbrains.com”添加到hosts文件中 二.浏览器打开 http://idea.lanyus.com,点击页面中的“获得注册码”,然后在注册时切换至 ...

  2. c++基础_字符串对比

    #include <iostream> #include <string.h> #include <algorithm> using namespace std; ...

  3. Django中配置自定义日志系统

  4. bzoj 3173 [Tjoi2013]最长上升子序列 (treap模拟+lis)

    [Tjoi2013]最长上升子序列 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 2213  Solved: 1119[Submit][Status] ...

  5. POJ1276 Cash Machine

    Time Limit: 1000MS   Memory Limit: 10000KB   64bit IO Format: %lld & %llu Description A Bank pla ...

  6. NOIP2013提高组D2T3 华容道

    n<=30 * m<=30 的地图上,0表示墙壁,1表示可以放箱子的空地.q<=500次询问,每次问:当空地上唯一没有放箱子的空格子在(ex,ey)时,把位于(sx,sy)的箱子移动 ...

  7. n个点中求任意两点组成斜率的最大值

    http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1100 首先按x坐标排序,然后相邻的三个点A,B,C 组成的三条直线必然有 ...

  8. Java DynamoDB 增加、删除、修改、查询

    准备jar包 <dependency> <groupId>com.amazonaws</groupId> <artifactId>aws-java-sd ...

  9. Eclipse完成Maven + Spring Boot + Mybatis + jsp

    Spring Boot 完成WEB项目开发 开发工具:eclipse 框架:Maven:Spring Boot:Mybatis 界面:jsp:javascript:css 前言: 在SpringBoo ...

  10. Ubuntu 16.04出现:qmake: could not exec '/usr/lib/x86_64-linux-gnu/qt4/bin/qmake': No such file or directory

    没有安装qt4-qmake,安装即可: sudo apt-get install qt4-qmake 参考: https://stackoverflow.com/questions/23703864/ ...