题目链接: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. Hanlp-地名识别调试方法详解

    HanLP收词特别是实体比较多,因此特别容易造成误识别.下边举几个地名误识别的例子,需要指出的是,后边的机构名识别也以地名识别为基础,因此,如果地名识别不准确,也会导致机构名识别不准确. 类型1 数字 ...

  2. Hadoop和Spark的Shuffer过程对比解析

    Hadoop Shuffer Hadoop 的shuffer主要分为两个阶段:Map.Reduce. Map-Shuffer: 这个阶段发生在map阶段之后,数据写入内存之前,在数据写入内存的过程就已 ...

  3. python在windows和linux下的安装和配置

    一.windows下安装python3.6 安装编辑器:Ecplise+pydev插件 Eclipse是写JAVA的IDE, 这样就可以通用了,学习代价小.  学会了Eclipse, 以后写Pytho ...

  4. ubuntu14中配置tomcat8

    在ubuntu14.04中配置tomcat8. 1.下载tomcat 地址:http://tomcat.apache.org/download-80.cgi ubuntu可以下载tar.gz类型的或者 ...

  5. vue去掉链接中的#

    在router.js中修改, const router = new VueRouter({ mode: 'history', routes: [...] })

  6. (十五)mybatis 逆向工程

    目录 为什么需要逆向工程 使用方法 如何读懂生成的代码 总结 为什么需要逆向工程 对于数据库中的那么多的表 ,基本的 CRUD 操作 ,以及 mybatis 需要使用的 接口.mapper ,这些工作 ...

  7. dp 状态压缩

    之前我们在讨论的dp形式当中, 大多数是对整数的动态规划, 然而对于集合而言呢 ? 我们使用 DFS 吗, 看起来也可以, 但是加上dp记忆 数组的 动态规划效率更高: 那么进一步讨论, 我们如何表示 ...

  8. VS code 的使用

    VS code 是一个非常不错的代码编辑器.它不依赖与任何编译器或者解释器,但却能高效的利用第三方编译器或解释器来给用户提供良好的代码编写环境. 我喜欢VS code的三点,丰富强大的插件,快捷的语法 ...

  9. DeepMind提出新型超参数最优化方法:性能超越手动调参和贝叶斯优化

    DeepMind提出新型超参数最优化方法:性能超越手动调参和贝叶斯优化 2017年11月29日 06:40:37 机器之心V 阅读数 2183   版权声明:本文为博主原创文章,遵循CC 4.0 BY ...

  10. django+uwsgi+nginx: websock 报502/400

    耽搁了近2个月,终于解决了,主要是nginx/uwsgi/django相关的配置: 一.django工程settings.py,添加 WEBSOCKET_FACTORY_CLASS = "d ...