题目链接:http://codeforces.com/contest/1058/problem/E

题意:给出 n 个数,对于一个选定的区间,区间内的数可以通过重新排列二进制数的位置得到一个新的数,问有多少个区间满足,区间内的数异或和为 0 。

题解:首先对于一个区间来说,区间内二进制为 1 的个数为奇数时显然不可能满足条件,先统计二进制为 1 的个数为偶数的区间总个数。而在一个区间内,如果某个数二进制下有 x 个 1 ,而区间内其他数的二进制 1 加起来小于 x ,则是不满足的,可以暴力去掉这些不合法的区间。因为一个数 <= 1e18,二进制位为 1 最多只有 59 位。

 #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define mst(a,b) memset((a),(b),sizeof(a))
#define mp(a,b) make_pair(a,b)
#define pi acos(-1)
#define pii pair<int,int>
#define pb push_back
const int INF = 0x3f3f3f3f;
const double eps = 1e-;
const int MAXN = 3e5 + ;
const int MAXM = 2e6 + ; int a[MAXN];
ll cnt[][MAXN]; int main() {
#ifdef local
freopen("data.txt", "r", stdin);
// freopen("data.txt", "w", stdout);
#endif
int n;
scanf("%d",&n);
cnt[][] = ;
int sum = ;
for(int i = ; i <= n; i++) {
ll b;
scanf("%lld",&b);
int num = ;
while(b) {
if(b & ) num++;
b >>= ;
}
a[i] = num;
sum += num;
cnt[][i] = cnt[][i - ], cnt[][i] = cnt[][i - ];
cnt[sum % ][i]++;
}
ll ans = ;
for(int i = ; i <= n; i++) {
if(i == || cnt[][i - ] - cnt[][i - ]) ans += cnt[][n] - cnt[][i - ];
else ans += cnt[][n] - cnt[][i - ];
int mn = min(n, i + ), mx = ;
sum = ;
for(int j = i; j <= mn; j++) {
sum += a[j];
mx = max(mx, a[j]);
if(sum % == && sum - mx < mx) ans--;
}
}
printf("%lld\n",ans);
return ;
}

Codeforces Round #512 (Div. 2, based on Technocup 2019 Elimination Round 1) E. Vasya and Good Sequences(DP)的更多相关文章

  1. Codeforces Round #512 (Div. 2, based on Technocup 2019 Elimination Round 1) C. Vasya and Golden Ticket 【。。。】

    任意门:http://codeforces.com/contest/1058/problem/C C. Vasya and Golden Ticket time limit per test 1 se ...

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

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

  3. Codeforces Round #517 (Div. 2, based on Technocup 2019 Elimination Round 2)

    Codeforces Round #517 (Div. 2, based on Technocup 2019 Elimination Round 2) #include <bits/stdc++ ...

  4. (AB)Codeforces Round #528 (Div. 2, based on Technocup 2019 Elimination Round

    A. Right-Left Cipher time limit per test 1 second memory limit per test 256 megabytes input standard ...

  5. Codeforces Round #517 (Div. 2, based on Technocup 2019 Elimination Round 2) D. Minimum path

    http://codeforces.com/contest/1072/problem/D bfs 走1步的最佳状态 -> 走2步的最佳状态 -> …… #include <bits/ ...

  6. Codeforces Round #517 (Div. 2, based on Technocup 2019 Elimination Round 2) D. Minimum path(字典序)

    https://codeforces.com/contest/1072/problem/D 题意 给你一个n*n充满小写字母的矩阵,你可以更改任意k个格子的字符,然后输出字典序最小的从[1,1]到[n ...

  7. Codeforces Round #528 (Div. 2, based on Technocup 2019 Elimination Round 4) C. Connect Three 【模拟】

    传送门:http://codeforces.com/contest/1087/problem/C C. Connect Three time limit per test 1 second memor ...

  8. Codeforces Round #522 (Div. 2, based on Technocup 2019 Elimination Round 3)B. Personalized Cup

    题意:把一长串字符串 排成矩形形式  使得行最小  同时每行不能相差大于等于两个字符 每行也不能大于20个字符 思路: 因为使得行最小 直接行从小到大枚举即可   每行不能相差大于等于两个字符相当于  ...

  9. Codeforces Round #522 (Div. 2, based on Technocup 2019 Elimination Round 3) C. Playing Piano

    题意:给出一个数列 a1 a2......an  让你构造一个序列(该序列取值(1-5)) 如果a(i+1)>a(i) b(i+1)>b(i) 如果a(i+1)<a(i)  那么b( ...

随机推荐

  1. pptpd的log整理

    前言: 最近有时候,我的pptpd会莫名崩掉.这时,在外边的我连不到内网,气的一比. 这时候,就需要去查一查log日志了.   所以就记录一下怎么调日志的: 1. 修改/etc/ppp/pptpd.o ...

  2. ubuntu/debian将sh改为bash

    1.  查看现在环境 可以看到,现在的默认环境是sh.我们想把它变为bash,可以这样做: 2. 运行sudo dpkg-reconfigure dash,出现以下画面: 这里提示我们是否要用默认的s ...

  3. Spring mybatis源码篇章-Mybatis主文件加载

    通过阅读源码对实现机制进行了解有利于陶冶情操,承接前文Spring mybatis源码篇章-SqlSessionFactory 前话 本文承接前文的内容继续往下扩展,通过Spring与Mybatis的 ...

  4. 原生js实现图片的3d效果

    <!doctype html><html lang="en"><head><meta charset="UTF-8"& ...

  5. php分页思路

    <?php class page{ public $nowPage=1; public $perPage=10; public $showPage=10; public $totalPage; ...

  6. github骚操作

    限制搜索 in关键词限制搜索范围 命令 说明 xxx in:name 项目名包含xxx的 xxx in:description 项目描述包含xxx的 xxx in:readme 项目的readme文件 ...

  7. 8-MySQL DBA笔记-测试基础

    第三部分 测试篇 测试需要掌握的知识面很广泛,本篇的关注点是数据库的性能测试和压力测试,对于其他领域的测试,由于涉猎不多,笔者就不做叙述了.DBA的工作职责之一就是评估软硬件,这往往是一项很耗时的工作 ...

  8. [转载]java中import作用详解

    [转载]java中import作用详解 来源: https://blog.csdn.net/qq_25665807/article/details/74747868 这篇博客讲的真的很清楚,这个作者很 ...

  9. for in和for of的区别

    for in:一般用于遍历普通对象(即没有部署Iterator接口),遍历的是属性. for of:ES6新增的遍历方式,能遍历大部分的类型,遍历的是值.for...of 允许你遍历 Arrays(数 ...

  10. express相关操作

    1.   安装应用生成器npm install express-generator –g 2.   生成项目Express --view=ejs myapp 3.   进入项目安装依赖包 npm in ...