Codeforces Round #512 (Div. 2, based on Technocup 2019 Elimination Round 1) E. Vasya and Good Sequences
题目链接
官网题解写的好清楚,和昨晚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]$中,和为偶数最大值大于总和一半的减去就行了。
- #include <bits/stdc++.h>
- using namespace std;
- typedef long long ll;
- const int maxn = 3e5 + ;
- int b[maxn];
- int sum[maxn];
- int odd[maxn], even[maxn];
- int main()
- {
- int n; scanf("%d", &n);
- for(int i = ; i <= n; i++)
- {
- ll x;
- scanf("%lld", &x);
- while(x)
- {
- if(x % 2LL == 1LL) b[i]++;
- x >>= 1LL;
- }
- //printf("%d\n", b[i]);
- }
- for(int i = n; i >= ; i--)
- {
- sum[i] = sum[i + ] + b[i];
- odd[i] = odd[i + ], even[i] = even[i + ];
- if(sum[i] % == ) even[i]++;
- else odd[i]++;
- }
- ll ans = ;
- for(int i = ; i <= n; i++) ///枚举左端点
- {
- if(sum[i] % == ) ans += even[i + ];
- else ans += odd[i + ];
- int mx = ;
- if(i == ) continue; ///i=0,统计的是右端点为n的区间
- for(int j = i; j <= min(n, i + ); j++)
- {
- mx = max(mx, b[j]);
- int tmp = sum[i] - sum[j + ];
- if((tmp % == ) && (mx + mx) > tmp) ans--;
- }
- }
- printf("%lld\n", ans);
- return ;
- }
Codeforces Round #512 (Div. 2, based on Technocup 2019 Elimination Round 1) E. Vasya and Good Sequences的更多相关文章
- 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 ...
- 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 #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++ ...
- (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 ...
- 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/ ...
- 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 ...
- 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 ...
- Codeforces Round #522 (Div. 2, based on Technocup 2019 Elimination Round 3)B. Personalized Cup
题意:把一长串字符串 排成矩形形式 使得行最小 同时每行不能相差大于等于两个字符 每行也不能大于20个字符 思路: 因为使得行最小 直接行从小到大枚举即可 每行不能相差大于等于两个字符相当于 ...
- 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( ...
随机推荐
- 爬虫4_python2
import urllib2 response = urllib2.urlopen("https://www.baidu.com") print response.read() 构 ...
- CPP-基础:strcpy之于C++(
以下对strcpy函数错误的是? char atr1[]="string"; ]; char *str3; char *str4="sting"; A.strc ...
- PAT (Basic Level) Practise (中文)-1031. 查验身份证(15)
PAT (Basic Level) Practise (中文)-1031. 查验身份证(15) http://www.patest.cn/contests/pat-b-practise/1031 一个 ...
- [CODEVS] 2193 数字三角形WW
数字三角形必须经过某一个点,使之走的路程和最大 从必须经过的点,向上向下分别DP两次的和即为答案. 还有一种思路是把和必须经过点同一行的设为-INF,这样就一定(大概)不会选择它们了. //Write ...
- 【DB_MySQL】 limit——取查询结果的子集
语法:select * from student limit beginIndex,length; 这里结果集的下标同数组一样从0开始,beginIndex表示起始位置,length表示从beginI ...
- ELK踩过的各种坑 6.4版本
一.elasticsearch 1.服务正常启动,但不能正常访问 [root@linux-node1 elasticsearch]# systemctl start elasticsearch [ro ...
- 蓝牙学习(3) Linux kernel部分Bluetooth HCI分析
在上文,https://blog.csdn.net/feiwatson/article/details/81712933中主要理解了在Kernel中USB adapter是如何实现USB设备驱动,以及 ...
- python爬虫(爬取段子)
python爬取段子 爬取某个网页的段子 第一步 不管三七二十一我们先导入模块 #http://baijiahao.baidu.com/s?id=1598724756013298998&wfr ...
- python--BOM和DOM
一. 介绍 什么是BOM和DOM? 简要答案:BOM是浏览器对象模型,用来获取或设置浏览器的属性.行为,例如:新建窗口.获取屏幕分辨率.浏览器版本号等. DOM是文档对象模型,用来获取或设置文档中标签 ...
- python--线程的其他方法
一 . current_thread的用法 import threading import time from threading import Thread, current_thread def ...