3518. 【NOIP2013模拟11.6A组】进化序列(evolve)

(File IO): input:evolve.in output:evolve.out

Time Limits: 1000 ms Memory Limits: 262144 KB

Description

Abathur采集了一系列Primal Zerg 的基因样本,这些基因构成了一个完整的进化链。为了方便,我们用A0,A1…An-1 这n 个正整数描述它们。

一个基因Ax 可以进化为序列中在它之后的基因Ay。这个进化的复杂度,等于Ax | Ax+1…| Ay的值,其中| 是二进制或运算。

Abathur 认为复杂度小于M 的进化的被认为是温和的。它希望计算出温和的进化的对数。

Input

第一行包含两个整数n,m。

接下来一行包含A0,A1…An-1 这n 个正整数,描述这n 个基因。

Output

第一行包含一个整数,表示温和的进化的对数。

Sample Input

4 6

1 3 5 1

Sample Output

2

Data Constraint

对于30% 的数据,1 <= n <=1000。

对于100% 的数据,1 <= n<= 100000,0 <= m <= 2^30,1<= Ai<= 2^30。

题解

两种解法:

一种是类似RMQ的倍增算法

另一种是……(我也不知道,有点像单调队列……反正是队列)

我用的是第二种,虽然不知道叫什么算法,但是也讲讲

用队列que表示当前选择

a [ i ] 表示第i位的1的个数

num表示当前进化复杂度

如果当前值x,x|num>m就把队首丢掉

代码

#include<cstdio>
#include<queue>
#include<cmath>
#define lowbit(a) ((a)&-(a))
#define qu(q) ((long)log2(lowbit(q)))
#define N 32
using namespace std;
queue<long>que;
long a[N];
int main()
{ long n,m,i,q,num,x,ans=0;
freopen("evolve.in","r",stdin);
freopen("evolve.out","w",stdout);
scanf("%ld%ld",&n,&m);
num=0;
for(i=1;i<=n;i++){
scanf("%ld",&x);
while((num|x)>m){
for(q=que.front();q;q^=lowbit(q)){
a[qu(q)]--;
if(!a[qu(q)])
num^=lowbit(q);
}
que.pop();
}
num|=x;
que.push(x);
for(q=x;q;q^=lowbit(q))
a[qu(q)]++;
ans+=que.size()-1;
}
printf("%ld\n",ans);
return 0;
}

JZOJ 3518. 【NOIP2013模拟11.6A组】进化序列(evolve)的更多相关文章

  1. JZOJ 3509. 【NOIP2013模拟11.5B组】倒霉的小C

    3509. [NOIP2013模拟11.5B组]倒霉的小C(beats) (File IO): input:beats.in output:beats.out Time Limits: 1000 ms ...

  2. JZOJ 3508. 【NOIP2013模拟11.5B组】好元素

    3508. [NOIP2013模拟11.5B组]好元素(good) (File IO): input:good.in output:good.out Time Limits: 2000 ms  Mem ...

  3. JZOJ 3505. 【NOIP2013模拟11.4A组】积木(brick)

    3505. [NOIP2013模拟11.4A组]积木(brick) (File IO): input:brick.in output:brick.out Time Limits: 1000 ms Me ...

  4. JZOJ 3526. 【NOIP2013模拟11.7A组】不等式(solve)

    3526. [NOIP2013模拟11.7A组]不等式(solve) (File IO): input:solve.in output:solve.out Time Limits: 1000 ms M ...

  5. [jzoj]3506.【NOIP2013模拟11.4A组】善良的精灵(fairy)(深度优先生成树)

    Link https://jzoj.net/senior/#main/show/3506 Description 从前有一个善良的精灵. 一天,一个年轻人B找到她并请他预言他的未来.这个精灵透过他的水 ...

  6. JZOJ【NOIP2013模拟联考14】隐藏指令

    JZOJ[NOIP2013模拟联考14]隐藏指令 题目 Description 在d维欧几里得空间中,指令是一个长度为2N的串.串的每一个元素为d个正交基的方向及反方向之一.例如,d = 1时(数轴) ...

  7. [jzoj 5343] [NOIP2017模拟9.3A组] 健美猫 解题报告 (差分)

    题目链接: http://172.16.0.132/senior/#main/show/5343 题目: 题解: 记旋转i次之后的答案为$ans_i$,分别考虑每个元素对ans数组的贡献 若$s_i& ...

  8. [JZOJ 4307] [NOIP2015模拟11.3晚] 喝喝喝 解题报告

    题目链接: http://172.16.0.132/senior/#main/show/4307 题目: 解题报告: 题目询问我们没出现坏对的连续区间个数 我们考虑从左到有枚举右端点$r$,判断$a[ ...

  9. 2017.07.11【NOIP提高组】模拟赛B组

    Summary 今天的比赛打得还不错,第一题被同桌灌输的贪心,纯模拟洗脑了,然后steal的看了一下,发现怎么也对不了,一直在检查.最后10分钟才找出反例,推出动态规划方程,没有想到怎么转移,比赛就结 ...

随机推荐

  1. python编程练习题目

    github上面的一个项目,分为level1,level2,level3 三个等级的难度. 题目地址 一部分中文翻译 python教程 剑指offer,python3实现 python进阶 练习题1: ...

  2. python-django项目-Linux系统建立django项目_20191117

    python-django项目-Linux系统建立django项目 1,Linux系统下面,cd /usr/local/lib/  看这个下面会有两个python版本,一个2.7,一个3.5,我们使用 ...

  3. Simple Random Sampling|representative sample|probability sampling|simple random sampling with replacement| simple random sampling without replacement|Random-Number Tables

    1.2 Simple Random Sampling Census, :全部信息 Sampling: 抽样方式: representative sample:有偏向,研究者选择自己觉得有代表性的sam ...

  4. vs2015的密钥

    最近一直提示VS要登陆,登陆完就说评估期已到,搞得很烦. VS2015 enterprise版本得密钥:  HM6NR-QXX7C-DFW2Y-8B82K-WTYJV    亲测有效!!! 专业版本的 ...

  5. LiauidCrystal

    1.begin()函数语法: lcd.begin(cols,rows) cols:列数: rows:行数: 2.print()函数,语法: lcd.print(data) lcd.print(data ...

  6. [LC] 12. Integer to Roman

    Roman numerals are represented by seven different symbols: I, V, X, L, C, D and M. Symbol Value I 1 ...

  7. [LC] 110. Balanced Binary Tree

    Given a binary tree, determine if it is height-balanced. For this problem, a height-balanced binary ...

  8. Office 365 的安装方法

    一.在线安装 进入网址 https://www.office.com/ 使用office账号登陆 1.点击右上角安装office应用,选择第二项 其他安装选项 2.选择安装语言 点击高级,选择安装版本 ...

  9. [LC] 24. Swap Nodes in Pairs

    Given a linked list, swap every two adjacent nodes and return its head. You may not modify the value ...

  10. try中定义的变量在finally中找不到

    凡是代码块中的变量,作用域都只在代码块中 https://blog.csdn.net/qq_20936333/article/details/81062966 问题: 解决: