B - Vasya and Good Sequences

思路:

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

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

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

如果区间长度大于128,第二个条件肯定满足,所以我们只要暴力区间长度小于128的就可以了

代码:

#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize(4)
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pi acos(-1.0)
#define LL long long
//#define mp make_pair
#define pb push_back
#define ls rt<<1, l, m
#define rs rt<<1|1, m+1, r
#define ULL unsigned LL
#define pll pair<LL, LL>
#define pii pair<int, int>
#define piii pair<pii, pii>
#define mem(a, b) memset(a, b, sizeof(a))
#define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define fopen freopen("in.txt", "r", stdin);freopen("out.txt", "w", stout);
//head const int N = 3e5 + ;
LL a[N];
int cnt[N], sum[N][];
int main() {
int n;
scanf("%d", &n);
for (int i = ; i <= n; i++) scanf("%lld", &a[i]);
for (int i = ; i <= n; i++) {
for (int j = ; j < ; j++) {
if(a[i] & (1LL << j)) cnt[i]++;
}
}
sum[][] = ;
sum[][] = ;
int tot = ;
for (int i = ; i <= n; i++) {
sum[i][] = sum[i-][];
sum[i][] = sum[i-][];
tot += cnt[i];
if(tot&) sum[i][]++;
else sum[i][]++;
}
LL ans = ;
for (int l = ; l <= n; l++) {
int up = min(l+, n);
int mx = -0x3f3f3f3f, tot = ;
for (int i = l; i <= up; i++) {
mx = max(mx, cnt[i]);
tot += cnt[i];
if(tot% == && tot >= mx*) ans++;
}
}
tot = ;
for (int i = ; i <= ; i++) tot += cnt[i];
for (int i = ; i <= n; i++) {
tot += cnt[i];
if(tot&) ans += sum[i-][];
else ans += sum[i-][];
}
printf("%lld\n", ans);
return ;
}

Codeforces 1053 B - Vasya and Good Sequences的更多相关文章

  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 ...

  2. Codeforces #550 (Div3) - G.Two Merged Sequences(dp / 贪心)

    Problem  Codeforces #550 (Div3) - G.Two Merged Sequences Time Limit: 2000 mSec Problem Description T ...

  3. [CF1030E]Vasya and Good Sequences

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

  4. [Codeforces 1053B] Vasya and Good Sequences

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

  5. [Codeforces 1058E] Vasya and Good Sequences

    [题目链接] https://codeforces.com/contest/1058/problem/E [算法] 显然 , 我们只需考虑序列中每个数的二进制表示下1的个数即可. 不妨令Ai表示第i个 ...

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

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

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

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

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

  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. mysql启动、关闭与登录

    按照上述三篇随笔中的方法安装mysql,其启动.关闭和登录方法如下. mysql启动基本原理:/etc/init.d/mysqld是一个shell启动脚本,启动后最终会调用mysql\bin\mysq ...

  2. JS截取字符串中数字

    今天项目中需要在一个字符串中截取一个数字,然后数字参与运算.搜了一下,有好多好用的方式截取字符串. 1,使用parseInt() var str ="4500元"; var num ...

  3. daemon进程fork一次和fork两次的区别?

    守护进程也称为精灵进程(Daemon),是运行在后台的一种特殊的进程.它独立于控制终端并且周期性的执行某种任务负等待处理某些发生的事件.因为他们没有控制终端,所以说他们是在后台运行的. 守护进程的特点 ...

  4. webpack对于引入的模块无法智能代码提示

    前端模块太多了,模块里的方法比较难记住,所以我们一般靠的都是IDE的代码提示. 但是有时候我们会发现对于引入的模块没有代码提示,我也安装了模块呀,为什么没有代码提示? 主要是package.json的 ...

  5. js 根据对象属性对数组进行按字母排序

    $scope.input.sort(compare('ticked','name')); var compare = function(ticked, name){ return function(a ...

  6. Flask学习【第9篇】:Flask-script组件

    Flask Script扩展提供向Flask插入外部脚本的功能,包括运行一个开发用的服务器,一个定制的Python shell,设置数据库的脚本,cronjobs,及其他运行在web应用之外的命令行任 ...

  7. 虚拟机极简配置manjaro gnome

    一.安装gnome启动到桌面后,卸载所有不必要的软件,减少系统大小 打开[增加/删除软件],找到要删除的软件卸载 ms-office ---微软在线办公软件 Thunderbird ---邮箱 kon ...

  8. word2010使用记录

    安装时提示: installer无法更新被保护的一个或多个文件, 解决方法是: 将三个dll文件,放在 c:\program files\common files\ms shared\web serv ...

  9. 远程调试Spring项目

    目录 服务端启动: 启动jar包: 使用环境变量参数调试jar包: 使用mvnDebug启动SpringMVC项目: 使用mvn启动: 使用Tomcat,非嵌入式启动: 客户端设置: IDEA设置: ...

  10. HIHOcoder1465 后缀自动机五·重复旋律8

    思路 后缀自动机求最长循环串 首先有一个常用的处理技巧,将串复制一遍,长度大于n的子串中就包含了一组循环子串 然后是后缀自动机如何处理最长公共子串的问题 维护两个变量,u和l,u代表当前位置的最长公共 ...