Codeforces 1053 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的更多相关文章
- 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 ...
- Codeforces #550 (Div3) - G.Two Merged Sequences(dp / 贪心)
Problem Codeforces #550 (Div3) - G.Two Merged Sequences Time Limit: 2000 mSec Problem Description T ...
- [CF1030E]Vasya and Good Sequences
[CF1030E]Vasya and Good Sequences 题目大意: 给定一个长度为\(n(n\le3\times10^5)\)的数列\(a_i(1\le a_i\le10^{18})\). ...
- [Codeforces 1053B] Vasya and Good Sequences
Link: Codeforces 1053B 传送门 Solution: 其实就是暴力 观察需要满足的条件: 1.个数和为偶数 2.最大个数不大于其它所有个数的和 如果只有第一个条件记录前缀和的奇偶性 ...
- [Codeforces 1058E] Vasya and Good Sequences
[题目链接] https://codeforces.com/contest/1058/problem/E [算法] 显然 , 我们只需考虑序列中每个数的二进制表示下1的个数即可. 不妨令Ai表示第i个 ...
- 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] = ...
- 2018.09.23 codeforces 1053B. Vasya and Good Sequences(前缀和)
传送门 考试的时候卡了一会儿. 显然这个答案只跟二进制位为1的数量有关. 还有一个显然的结论. 对于一个区间[l,r][l,r][l,r],如果其中单个数二进制位为1的数量最大值不到区间所有数二进制位 ...
- Codeforces Round #512 (Div. 2, based on Technocup 2019 Elimination Round 1) E. Vasya and Good Sequences
题目链接 官网题解写的好清楚,和昨晚Aguin说的一模一样…… 这题只和每个数1的个数有关,设每个数1的个数的数组为$b$,就是首先一段如果是好的,要满足两个条件: 1.这一段$b$数组和为偶数,因为 ...
随机推荐
- mysql备份与还原-mysqldump备份、mysql与source还原
以下都以在linux操作系统上的mysql为例 mysqldump备份 mysqldump实际就是将数据库中的数据转化为建库.建表和插入记录的sql语句 1.备份一个数据库 [或其中几个表],不指定表 ...
- P2114 [NOI2014]起床困难综合症(二进制)
P2114 [NOI2014]起床困难综合症 我们开始设俩数,一个二进制表示全是1,另一个全是0(就是2147483647 和 0 辣) 蓝后跑一遍门 于是最后有4种情况 1->0,1-> ...
- Net SMTP QQ 发送邮件
调用DEMO var currUser = new List<string> { "123@qq.com" , "123@qq.com" , &qu ...
- windows线程池之I/O完成端口(IOCP)
对于这个学习主要参考博客 http://blog.csdn.net/neicole/article/details/7549497
- 2018-2019-2 《网络对抗技术》Exp3 免杀原理与实践 20165211
目录 2018-2019-2 <网络对抗技术>Exp3 免杀原理与实践 20165211 1. 基础问题回答 (1)杀软是如何检测出恶意代码的? (2)免杀是做什么? (3)免杀的基本方法 ...
- 20145325张梓靖 《网络对抗技术》 Web安全基础实践
20145325张梓靖 <网络对抗技术> Web安全基础实践 实验内容 使用webgoat进行XSS攻击.CSRF攻击.SQL注入 XSS攻击:Stored XSS Attacks.Ref ...
- 20145325张梓靖 《网络对抗技术》 Web基础
20145325张梓靖 <网络对抗技术> Web基础 实验内容 开启apahce,设计web前端HTML 设计web前端javascipt 设计web后端mysql 设计web后端php ...
- Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals) Problem D (Codeforces 831D) - 贪心 - 二分答案 - 动态规划
There are n people and k keys on a straight line. Every person wants to get to the office which is l ...
- linux tmux 工具使用 tmux.conf 文件
set -g prefix ^a unbind ^b bind a send-prefix unbind '"' bind - splitw -v unbind % bind \ split ...
- topcoder srm 530 div1
problem1 link 对于每个还未切掉的‘X’用cutter作用一次.从左上角到右下角,依次判断即可. problem2 link 首先,如果一个顶点不能从0到达或者不能到达节点$n-1$,那么 ...