[Codeforces 1058E] Vasya and Good Sequences
[题目链接]
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的更多相关文章
- [Codeforces 1053B] Vasya and Good Sequences
Link: Codeforces 1053B 传送门 Solution: 其实就是暴力 观察需要满足的条件: 1.个数和为偶数 2.最大个数不大于其它所有个数的和 如果只有第一个条件记录前缀和的奇偶性 ...
- 2018.09.23 codeforces 1053B. Vasya and Good Sequences(前缀和)
传送门 考试的时候卡了一会儿. 显然这个答案只跟二进制位为1的数量有关. 还有一个显然的结论. 对于一个区间[l,r][l,r][l,r],如果其中单个数二进制位为1的数量最大值不到区间所有数二进制位 ...
- Codeforces 1053 B - Vasya and Good Sequences
B - Vasya and Good Sequences 思路: 满足异或值为0的区间,必须满足一下条件: 1.区间中二进制1的个数和为偶数个; 2.区间二进制1的个数最大值的两倍不超过区间和. 如果 ...
- 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 ...
- [CF1030E]Vasya and Good Sequences
[CF1030E]Vasya and Good Sequences 题目大意: 给定一个长度为\(n(n\le3\times10^5)\)的数列\(a_i(1\le a_i\le10^{18})\). ...
- CodeForces - 837E - Vasya's Function | Educational Codeforces Round 26
/* CodeForces - 837E - Vasya's Function [ 数论 ] | Educational Codeforces Round 26 题意: f(a, 0) = 0; f( ...
- 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 个数,对于一个选定的区间,区间内的数可以通过重新排列二进制数的位置得到一个新的数,问 ...
- Codeforces Round #512 E - Vasya and Good Sequences
有时候觉得自己就是个思路搬运机,只会搬运思路 这个题首先说了求的是好区间的个数, 好区间满足条件: 1.二进制位1的数量和为偶数 2.w[i]表示a[i]的二进制上1的个数 ,sum[i] = ...
- Codeforces Round #512 (Div. 2, based on Technocup 2019 Elimination Round 1) E. Vasya and Good Sequences
题目链接 官网题解写的好清楚,和昨晚Aguin说的一模一样…… 这题只和每个数1的个数有关,设每个数1的个数的数组为$b$,就是首先一段如果是好的,要满足两个条件: 1.这一段$b$数组和为偶数,因为 ...
随机推荐
- linux下nginx、php和mysql安装配置
一.安装nginx 安装nginx yum install -y epel-release yum install nginx -y 查看nginx软件包包括了哪些文件 rpm -ql nginx 启 ...
- 把wav文件等时长切割
ffmpeg -i somefile.mp3 -f segment -segment_time 1800 -c copy out%03d.mp3 segment_time 是切割时长,单位秒
- C#NumberFormatInfo类
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAA0sAAAD2CAIAAACImosXAAAgAElEQVR4nOy9V3Nk13X+vTt3owPSJJ ...
- Python学习之单继承与多继承
继承 面向对象编程语言的一个主要功能就是“继承”. 继承是指这样一种能力:它可以使用现有类的所有功能,并在无需重新编写原来的类的情况下对这些功能进行扩展. (1) 单继承:python同时支持类的继承 ...
- 3D标签云
一.圆的坐标表达式 for(var i = 0;i < len;i++){ degree = (2*(k+1)-1)/len - 1;a = Math.acos(degree);//这样取得弧度 ...
- 【02】AJAX XMLHttpRequest对象
AJAX XMLHttpRequest对象 XMLHttpRequest 对象用于与服务器交换数据,能够在不重新加载整个网页(刷新)的情况下,对网页进行部分更新. XMLHttpRequest 对 ...
- 牛客网sql练习
一建表语句 /* Navicat MySQL Data Transfer Source Server : test Source Server Version : 50717 Source Host ...
- 如何抓取崩溃的log日志
4.手机录屏工具的推荐 Andriod:录屏大师,易录屏等等. iOS:AirPlayer,iTools. 5.如何抓取崩溃的log日志? android闪退获取日志方法: 1.下载adb工具包 2. ...
- 全文搜索(AB-2)-权重
概念 权重是一个相对的概念,针对某一指标而言.某一指标的权重是指该指标在整体评价中的相对重要程度.权重是要从若干评价指标中分出轻重来,一组评价指标体系相对应的权重组成了权重体系. 释义 等同于比重 ...
- hdu - 1072 Nightmare(bfs)
http://acm.hdu.edu.cn/showproblem.php?pid=1072 遇到Bomb-Reset-Equipment的时候除了时间恢复之外,必须把这个点做标记不能再走,不然可能造 ...