Codeforces Round #512 E - Vasya and Good Sequences
有时候觉得自己就是个思路搬运机,只会搬运思路
这个题首先说了求的是好区间的个数, 好区间满足条件: 1、二进制位1的数量和为偶数 2、w[i]表示a[i]的二进制上1的个数 ,sum[i] = w[1] + ... + w[i],对于l-r区间上任意一个位置j,w[j] < sum[r] - sum[l] - w[j]
设置一个dp[n][2] 数组,dp[i][0]代表 以i为结尾的,区间内二进制1的个数和为偶数的 区间个数
dp[i][1]代表 以i为结尾的,区间内二进制1的个数和为奇数的 区间个数
然后再用dp[i][0] - 所有不满足条件2的区间,把所有满足的区间求和即可
这个1<=a[i] <= 1e8 1e8比这个long long要小,60二进制位就可以保存, 所以这个 l - r 这个区间 最大的w[j] 其实也就是60不到,最小的w[i] 也是1 ,所以当你这个区间长度大于60,必定满足条件2
附上我丑陋无比的ac代码
#include<iostream>
#include<queue>
#include<cstring>
#include<vector>
#include<cstdio>
#include<cmath>
#include<map>
#include<string>
using namespace std;
#define ll long long
#define se second
#define fi first
int n;
const int maxn = ;
long long arr[maxn];
int w[maxn];
int sum[maxn];
int dp[maxn][];
int main()
{
memset(w,,sizeof(w));
scanf("%d",&n);
for(int i = ; i <= n; ++i)
{
scanf("%lld",arr+i);
long long k = ;
for(int j = ; j < ; ++j, k <<= )
{
if( k & arr[i] )
w[i] ++;
}
//cout << w[i] << endl;
}
dp[][] = dp[][] = dp[][] = dp[][] = ;
for(int i = ; i <= n; ++i)
{
//cout << w[i] << endl;
if(w[i] % == )
{
dp[i][] = dp[i-][]+(w[i-]%);
dp[i][] = dp[i-][]+!(w[i-]%);
}
else
{
dp[i][] = dp[i-][]+!(w[i-]%);
dp[i][] = dp[i-][]+(w[i-]%);
}
}
ll ans = ;
for(int i = ; i <= n; ++i)
{
ll add = ;
ll mx = w[i];
ll sum = w[i];
for(int j = i-; j >= && i-j<=; --j)
{
if(mx < w[j]) mx = w[j];
sum += w[j];
if(mx > sum - mx && sum % == )
add --;
}
//cout << dp[i][0] << endl;
//cout << add << endl;
add += dp[i][];
ans += add;
}
printf("%lld\n",ans);
}
Codeforces Round #512 E - Vasya and Good Sequences的更多相关文章
- Codeforces Round #512 D - Vasya and Triangle
D - Vasya and Triangle #include<bits/stdc++.h> using namespace std; #define LL long long LL gc ...
- 【前行】◇第3站◇ Codeforces Round #512 Div2
[第3站]Codeforces Round #512 Div2 第三题莫名卡半天……一堆细节没处理,改一个发现还有一个……然后就炸了,罚了一啪啦时间 Rating又掉了……但是没什么,比上一次好多了: ...
- 数学 Codeforces Round #219 (Div. 2) B. Making Sequences is Fun
题目传送门 /* 数学:这题一直WA在13组上,看了数据才知道是计算cost时超long long了 另外不足一个区间的直接计算个数就可以了 */ #include <cstdio> #i ...
- 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 (Div. 2, based on Technocup 2019 Elimination Round 1) E. Vasya and Good Sequences
题目链接 官网题解写的好清楚,和昨晚Aguin说的一模一样…… 这题只和每个数1的个数有关,设每个数1的个数的数组为$b$,就是首先一段如果是好的,要满足两个条件: 1.这一段$b$数组和为偶数,因为 ...
- 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) D. Vasya and Triangle
参考了别人的思路:https://blog.csdn.net/qq_41608020/article/details/82827632 http://www.cnblogs.com/qywhy/p/9 ...
- Codeforces Round #512 (Div. 2) D.Vasya and Triangle 数学
题面 题意:给你n,m,k,在你在(0,0)到(n,m)的矩形内,选3个格点(x,y都是整数),使得三角形面积为n*m/k,不能找到则输出-1 题解:由毕克定理知道,格点多边形的面积必为1/2的整数倍 ...
- Codeforces Round #512 (Div. 2) D. Vasya and Triangle(几何+思维)
题目 题意: 给出 n,m,k ,让你在长为 n,宽为 m 的坐标系里构建一个三角形,使得面积= n*m/k.如果存在,输出“YES”,输出三角形三个顶点的坐标: 如果不存在,输出“NO”. 思路: ...
随机推荐
- hive的使用
1,前言 书接上回,接着对上一个hive安装后环境下的hive使用.
- 低级sql语法错误: BadSqlGrammarException
at org.springframework.boot.SpringApplication.callRunners(SpringApplication.java:760) at org.springf ...
- V2Ray断流异常
V2Ray断流异常 1. 问题描述 最近一段时间发现,代理十分不稳定,经常出现“断流”,具体表现为:打开需要代理的站点,需要访问两次,第一次访问失败,需要再刷新一次.查看错误日志内容: Proxy ...
- python中configpraser模块
configparser 模块 解析配置文件模块 什么是配置文件? 用于编写程序的配置信息的文件 什么是配置信息? 为了提高程序的扩展性 #configparser模块的使用 #首先我们需要知道配 ...
- Spring Boot文档维护:集成Swagger2
一.Swagger简介 在日常的工作中,我们往往需要给前端(WEB端.IOS.Android)或者第三方提供接口,这个时我们就需要提供一份详细的API说明文档.但维护一份详细的文档可不是一件简单的事情 ...
- 二维凸包 Graham扫描算法
题目链接: http://poj.org/problem?id=1113 求下列点的凸包 求得凸包如下: Graham扫描算法: 找出最左下的点,设为一号点,将其它点对一号点连线,按照与x轴的夹角大小 ...
- oracle 表空间创建和删除
oracle数据库:数据库对象以及表数据都存储在表空间中,创建用户时可以指定对应的表空间.这样用户可以在各自的表空间中操作数据,互不干扰. 1. 表空间创建 若不清楚表空间对应文件的路径,可以登录系统 ...
- react组件回顶部
在挂载更新里面判断滚动条的距离(滚动条不能overflow: auto 踩坑) componentDidMount(){ window.addEventListener('scroll' , ()=& ...
- 目前php连接mysql的主要方式
mysqli和PDO, 其中mysqli可以有面向过程,面向对象两种方式.而pdo只有面向对象的方式. <?php // $mysql_server = "localhost" ...
- CentOS7 安装oracle客户端
1.本机环境CentOS7 64 [root@localhost etc]# uname -a Linux localhost.localdomain 3.10.0-693.el7.x86_64 #1 ...