JZOJ 7.11B组第三题 进化序列

本文介绍了一种计算温和基因进化对数的方法,通过使用线段树维护区间中的二进制或运算值,实现对特定进化复杂度的快速判断。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

题目:

Abathur采集了一系列Primal Zerg 的基因样本,这些基因构成了一个完整的进化链。为了方便,我们用A0,A1...An-1 这n 个正整数描述它们。一个基因Ax 可以进化为序列中在它之后的基因Ay。这个进化的复杂度,等于Ax | Ax+1...| Ay的值,其中| 是二进制或运算。Abathur 认为复杂度小于M 的进化的被认为是温和的。它希望计算出温和的进化的对数。

Input:

4 6

1 3 5 1
output:

2

分析:

此题可以暴力水解。用线段树来维护区间中a[x]xora[x+1]……a[x+100]的值,每隔一百取一波,用来缩短时间。然后如果下一次再多一百便s[y]>m,那么便开始for找到临界点。最后不断inc一下ans即可。

代码:

const
  maxn=100000;


var
  a,sum:array [0..maxn] of longint;
  n,m:longint;
  ans:int64;


procedure init;
var
  i,j:longint;
begin
  readln(n,m);
  for i:=1 to n do
    read(a[i]);
  for i:=1 to n do
    begin
      sum[i]:=a[i];
      for j:=i+1 to i+100 do
        sum[i]:=sum[i] or a[j];
    end;
end;


procedure main;
var
  i,j,section,back:longint;
  now:int64;
begin
  for i:=1 to n do
    begin
      now:=0;
      section:=i;
      if i+100<=n then
        while true do
          begin
            if now or sum[section]>m then
              break;
            now:=now or sum[section];
            inc(section,101);
            if section+100>n then
              break;
          end;
      if section>i then
        inc(ans,section-i-1);
      back:=0;
      for j:=section to n do
        begin
          if now or a[j]>m then
            break;
          inc(back);
          now:=now or a[j];
        end;
     if back>0 then
       if section=i then
         inc(ans,back-1)
       else
         inc(ans,back);
    end;
  write(ans);
end;


begin
  assign(input,'evolve.in');reset(input);
  assign(output,'evolve.out');rewrite(output);
  init;
  main;
  close(input);close(output);
end.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值