题目链接

官网题解写的好清楚,和昨晚Aguin说的一模一样……

这题只和每个数1的个数有关,设每个数1的个数的数组为$b$,就是首先一段如果是好的,要满足两个条件:

1.这一段$b$数组和为偶数,因为奇数总会多出一个1,消不掉。

2.这一段$b$数组中最大的要小于等于这一段总和的一半,因为自己里面的1和自己不能消。

有了这两个条件,先处理第一个条件,做法是枚举左端点,然后统计合法的右端点的个数,就$odd$和$even$数组统计后缀和为奇还是偶,偶-偶,奇-奇就好了,这样能够保证$[l,r]$区间是偶数。

再处理第二个条件,因为每个数$<=10^{18}$,所以最多有60个1,而且每个数不为$0$,所以每个数最少有一个1,那$[l,r]$区间长度大于60后,$b$数组的最大值一定小于等于总和的一半,所以只要把$r$在$[l,l+60]$中,和为偶数最大值大于总和一半的减去就行了。

  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. typedef long long ll;
  4. const int maxn = 3e5 + ;
  5. int b[maxn];
  6. int sum[maxn];
  7. int odd[maxn], even[maxn];
  8. int main()
  9. {
  10. int n; scanf("%d", &n);
  11. for(int i = ; i <= n; i++)
  12. {
  13. ll x;
  14. scanf("%lld", &x);
  15. while(x)
  16. {
  17. if(x % 2LL == 1LL) b[i]++;
  18. x >>= 1LL;
  19. }
  20. //printf("%d\n", b[i]);
  21. }
  22. for(int i = n; i >= ; i--)
  23. {
  24. sum[i] = sum[i + ] + b[i];
  25. odd[i] = odd[i + ], even[i] = even[i + ];
  26. if(sum[i] % == ) even[i]++;
  27. else odd[i]++;
  28. }
  29. ll ans = ;
  30. for(int i = ; i <= n; i++) ///枚举左端点
  31. {
  32. if(sum[i] % == ) ans += even[i + ];
  33. else ans += odd[i + ];
  34. int mx = ;
  35. if(i == ) continue; ///i=0,统计的是右端点为n的区间
  36. for(int j = i; j <= min(n, i + ); j++)
  37. {
  38. mx = max(mx, b[j]);
  39. int tmp = sum[i] - sum[j + ];
  40. if((tmp % == ) && (mx + mx) > tmp) ans--;
  41. }
  42. }
  43. printf("%lld\n", ans);
  44. return ;
  45. }

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

  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(DP)

    题目链接:http://codeforces.com/contest/1058/problem/E 题意:给出 n 个数,对于一个选定的区间,区间内的数可以通过重新排列二进制数的位置得到一个新的数,问 ...

  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. 爬虫4_python2

    import urllib2 response = urllib2.urlopen("https://www.baidu.com") print response.read() 构 ...

  2. CPP-基础:strcpy之于C++(

    以下对strcpy函数错误的是? char atr1[]="string"; ]; char *str3; char *str4="sting"; A.strc ...

  3. PAT (Basic Level) Practise (中文)-1031. 查验身份证(15)

    PAT (Basic Level) Practise (中文)-1031. 查验身份证(15) http://www.patest.cn/contests/pat-b-practise/1031 一个 ...

  4. [CODEVS] 2193 数字三角形WW

    数字三角形必须经过某一个点,使之走的路程和最大 从必须经过的点,向上向下分别DP两次的和即为答案. 还有一种思路是把和必须经过点同一行的设为-INF,这样就一定(大概)不会选择它们了. //Write ...

  5. 【DB_MySQL】 limit——取查询结果的子集

    语法:select * from student limit beginIndex,length; 这里结果集的下标同数组一样从0开始,beginIndex表示起始位置,length表示从beginI ...

  6. ELK踩过的各种坑 6.4版本

    一.elasticsearch 1.服务正常启动,但不能正常访问 [root@linux-node1 elasticsearch]# systemctl start elasticsearch [ro ...

  7. 蓝牙学习(3) Linux kernel部分Bluetooth HCI分析

    在上文,https://blog.csdn.net/feiwatson/article/details/81712933中主要理解了在Kernel中USB adapter是如何实现USB设备驱动,以及 ...

  8. python爬虫(爬取段子)

    python爬取段子 爬取某个网页的段子 第一步 不管三七二十一我们先导入模块 #http://baijiahao.baidu.com/s?id=1598724756013298998&wfr ...

  9. python--BOM和DOM

    一. 介绍 什么是BOM和DOM? 简要答案:BOM是浏览器对象模型,用来获取或设置浏览器的属性.行为,例如:新建窗口.获取屏幕分辨率.浏览器版本号等. DOM是文档对象模型,用来获取或设置文档中标签 ...

  10. python--线程的其他方法

    一 . current_thread的用法 import threading import time from threading import Thread, current_thread def ...