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. django ORM常用查询条件

    假设有一个模型 class Article(models.Model): title=models.CharField(max_length=50) content=models.TextField( ...

  2. 被fancybox坑的心路历程

    今天项目中需要使用fancybox来展示图片,但是使用中发现fancybox没起作用,点击图片直接刷新了页面! fancybox的原理是通过给a标签绑定事件,使得a标签不在是直接跳转链接,而是把链接中 ...

  3. 鸡兔同笼问题(Java)

    问题描述:编程解决鸡兔同笼问题,笼子中鸡兔共有35只,94只脚,求有鸡和兔各有几只 我的代码: /** * 鸡兔同笼问题 * @author Administrator * */ public cla ...

  4. 谈论linux同组多用户操作问题

    同组多用户,最先起到什么作用这个我也是不明白的, 然后乱搞了一堆, 下面我做个笔记帮组日后分析. 一个用户组承载多个用户, 像这样 这是我原先的思路.然后就是chenglee用户和chenglee12 ...

  5. Android之udp传输

    注意除了添加Internet权限外,还要添加两行代码 StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder().detectDi ...

  6. 对象new和不new的理解

    1.现象 在一个线程类[QObject]中声明一个对象QTimer,[不new,直接声明],在槽函数中timer.start() 报警告:不能跨线程调用对象 2.分析 不使用new的方式,直接A a; ...

  7. 89. a^b【快速幂模板】

    a^b Description 求 aa 的 bb 次方对 pp 取模的值. 输入格式 三个整数 a,b,pa,b,p ,在同一行用空格隔开. 输出格式 输出一个整数,表示a^b mod p的值. 数 ...

  8. CF1131D tarjan,拓扑

    题目链接 541div2 http://codeforces.com/contest/1131/problem/D 思路 给出n序列和m序列的相对大小关系 构造出最大值最小的序列 缩点+拓扑 小的向大 ...

  9. Docker 命令收集

    Docker 命令收集 1.删除所有容器 docker rm $(docker ps -a -q) 2.删除所有镜像 docker rmi $(docker images -q) 3.启动镜像 doc ...

  10. 【安装】Redis4.0.10在Linux环境搭建

    1.下载Redis后上传到指定目录 2.解压 tar -zxvf redis-4.0.10.tar.gz 3.进入加压后的目录并编译 cd redis-4.0.10 make 4.进入src目录安装 ...