[Codeforces 1053B] Vasya and Good Sequences
Link:
Solution:
其实就是暴力
观察需要满足的条件:
1、个数和为偶数
2、最大个数不大于其它所有个数的和
如果只有第一个条件记录前缀和的奇偶性即可,接下来考虑去除不符合第二个条件的区间
由于一个数最大有60个1且每个数至少有1个1,因此只要暴力查询区间长度小于60的区间即可
Code:
#include <bits/stdc++.h> using namespace std;
#define X first
#define Y second
#define pb push_back
typedef double db;
typedef long long ll;
typedef pair<int,int> P;
const int MAXN=5e5+;
ll n,x,cnt[MAXN],pre[MAXN],odd,even,res; int main()
{
scanf("%d",&n);
for(int i=;i<=n;i++)
{
scanf("%lld",&x);
while(x) cnt[i]+=x&,x>>=;
}
for(int i=;i<=n;i++)
pre[i]=pre[i-]+cnt[i]; for(int i=;i<=n;i++)
{
if(pre[i]%==)
res+=even+,even++;
else res+=odd,odd++;
res-=(pre[i]%==pre[i-]%);
}
for(int i=;i<=n;i++)
{
ll sum=cnt[i],mx=cnt[i];
for(int j=i-;j>=&&j>=i-;j--)
{
sum+=cnt[j];mx=max(cnt[j],mx);
if(mx>sum-mx&&sum%==) res--;
}
}
printf("%lld",res);
return ;
}
[Codeforces 1053B] Vasya and Good Sequences的更多相关文章
- 2018.09.23 codeforces 1053B. Vasya and Good Sequences(前缀和)
传送门 考试的时候卡了一会儿. 显然这个答案只跟二进制位为1的数量有关. 还有一个显然的结论. 对于一个区间[l,r][l,r][l,r],如果其中单个数二进制位为1的数量最大值不到区间所有数二进制位 ...
- [Codeforces 1058E] Vasya and Good Sequences
[题目链接] https://codeforces.com/contest/1058/problem/E [算法] 显然 , 我们只需考虑序列中每个数的二进制表示下1的个数即可. 不妨令Ai表示第i个 ...
- Codeforces 1053 B - Vasya and Good Sequences
B - Vasya and Good Sequences 思路: 满足异或值为0的区间,必须满足一下条件: 1.区间中二进制1的个数和为偶数个; 2.区间二进制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 ...
- [CF1030E]Vasya and Good Sequences
[CF1030E]Vasya and Good Sequences 题目大意: 给定一个长度为\(n(n\le3\times10^5)\)的数列\(a_i(1\le a_i\le10^{18})\). ...
- CodeForces - 837E - Vasya's Function | Educational Codeforces Round 26
/* CodeForces - 837E - Vasya's Function [ 数论 ] | Educational Codeforces Round 26 题意: f(a, 0) = 0; f( ...
- 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 #512 E - Vasya and Good Sequences
有时候觉得自己就是个思路搬运机,只会搬运思路 这个题首先说了求的是好区间的个数, 好区间满足条件: 1.二进制位1的数量和为偶数 2.w[i]表示a[i]的二进制上1的个数 ,sum[i] = ...
- Codeforces Round #512 (Div. 2, based on Technocup 2019 Elimination Round 1) E. Vasya and Good Sequences
题目链接 官网题解写的好清楚,和昨晚Aguin说的一模一样…… 这题只和每个数1的个数有关,设每个数1的个数的数组为$b$,就是首先一段如果是好的,要满足两个条件: 1.这一段$b$数组和为偶数,因为 ...
随机推荐
- 【游记】NOIP 2017
时间:2017.11.11~2017.11.12 地点:广东省广州市第六中学 Day1 T1:看到题目,心想这种题目也能放在T1? 这个结论我之前遇到过至少3次,自己也简单证明过.初见是NOIP200 ...
- RabbitMq related
# RabbitMq related Integration of message queuing tools with systems is the usual solution to handle ...
- 联系博主 Contact
李莫 / Ray OI 蒟蒻一只 / A Player of Olympiad in Informatics QQ:740929894 邮箱 / Email :rayking2017@outlook. ...
- JS中的实例方法与静态方法
一.静态方法与实例方法的例子: 我们先来看一个例子来看一下JS中的静态方法和实例方法到底是什么 静态方法: function A(){} A.sayMeS=function(){ console.lo ...
- div+css实现表头固定内容滚动表格
<div class="m-demo"> <table> <thead> <tr><th>定宽a</th>& ...
- 宿主机mount虚拟机镜像文件
转载 mount挂载虚拟机镜像文件 使用mount挂载ubuntu虚拟机所在的img文件的时候,执行: “sudo mount -o loop xxx.img /mnt/xxx”, 系统提示: “mo ...
- abp 调试
概要 研究Abp(ASP.NET Boilerplate)框架有几个月了,从一遍遍的看官方文档,到现在看源码,一路走来学习了很多知识. 很多新手都很关心源码如何调试,我也是如此,在反复看Debuggi ...
- AspxGridView在cell内显示颜色
protected void master_HtmlDataCellPrepared(object sender, ASPxGridViewTableDataCellEventArgs e) { if ...
- aspxgridview export导出数据,把true显示成‘是’
项目原因,数据库中的数据是‘true’还有‘false’,但是在页面上要显示为‘是否’,导出来的时候也是要显示成‘是否’ 要在web页面当中显示成‘是否’,只要在gridview的CustomColu ...
- 动画基础--基于Core Animation(3)
参考:https://zsisme.gitbooks.io/ios-/content/ 前面的文章动画基础--基于Core Animation(1),动画基础--基于Core Animation(2) ...