题目大意

  给出两个\(01\)序列\(A\)和\(B\)

  汉明距离定义为两个长度相同的序列中,有多少个对应位置上的数字不一样

  \(00111\) 和 \(10101\)的距离为\(2\)

  \(Q\)次询问,每次询问给出\(p_1,p_2,len\)

  求\(a_{p_1},a_{p_1+1}\ldots a_{p_1+len−1}\)和\(b_{p_1},b_{p_1+1}\ldots b_{p_1+len−1}\)两个子串的汉明距离

  \(n\leq 2\times{10}^5,q\leq 4\times {10}^5\)

题解

  wys【挑战】弱化版

  暴力碾分块系列

  把\(a_x\ldots a_{x+63}\)压成一个\(64\)位整数,每次暴力统计。

  时间复杂度:\(O(\frac{nq}{64})\)

代码

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cstdlib>
#include<ctime>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
char s1[200010];
char s2[200010];
ull a[200010];
ull b[200010];
int cnt[100010];
int count(ull x)
{
return cnt[x&0xffff]+cnt[(x>>16)&0xffff]+cnt[(x>>32)&0xffff]+cnt[(x>>48)&0xffff];
}
int main()
{
int n,m,q;
scanf("%s%s%d",s1+1,s2+1,&q);
n=strlen(s1+1);
m=strlen(s2+1);
int i;
for(i=n;i>=1;i--)
a[i]=(a[i+1]>>1)|(s1[i]=='1'?(1ll<<63):0);
for(i=m;i>=1;i--)
b[i]=(b[i+1]>>1)|(s2[i]=='1'?(1ll<<63):0);
cnt[0]=0;
for(i=1;i<(1<<16);i++)
cnt[i]=cnt[i>>1]+(i&1);
int x,y,l;
for(i=1;i<=q;i++)
{
scanf("%d%d%d",&x,&y,&l);
x++;
y++;
int ans=0;
while(l>=64)
{
ans+=count(a[x]^b[y]);
x+=64;
y+=64;
l-=64;
}
if(l)
ans+=count((a[x]^b[y])>>(64-l));
printf("%d\n",ans);
}
return 0;
}

【CF472G】Design Tutorial 压位的更多相关文章

  1. cf 472G Design Tutorial: Increase the Constraints 分块+压位/FFT

    题目大意 给出两个\(01\)序列\(A\)和\(B\) 哈明距离定义为两个长度相同的序列中,有多少个对应位置上的数字不一样 "00111" 和 "10101" ...

  2. Codeforces #270 D. Design Tutorial: Inverse the Problem

    http://codeforces.com/contest/472/problem/D D. Design Tutorial: Inverse the Problem time limit per t ...

  3. codevs 3119 高精度练习之大整数开根 (各种高精+压位)

    /* codevs 3119 高精度练习之大整数开根 (各种高精+压位) 二分答案 然后高精判重 打了一个多小时..... 最后还超时了...压位就好了 测试点#1.in 结果:AC 内存使用量: 2 ...

  4. 压位加速-poj-2443-Set Operation

    题目链接: http://poj.org/problem?id=2443 题目意思: 有n个集合(n<=1000),每个集合有m个数ai(m<=10000,1=<ai<=100 ...

  5. cf472D Design Tutorial: Inverse the Problem

    D. Design Tutorial: Inverse the Problem time limit per test 2 seconds memory limit per test 256 mega ...

  6. cf472C Design Tutorial: Make It Nondeterministic

    C. Design Tutorial: Make It Nondeterministic time limit per test 2 seconds memory limit per test 256 ...

  7. cf472B Design Tutorial: Learn from Life

    B. Design Tutorial: Learn from Life time limit per test 1 second memory limit per test 256 megabytes ...

  8. cf472A Design Tutorial: Learn from Math

    A. Design Tutorial: Learn from Math time limit per test 1 second memory limit per test 256 megabytes ...

  9. Codeforces Round #270--B. Design Tutorial: Learn from Life

    Design Tutorial: Learn from Life time limit per test 1 second memory limit per test 256 megabytes in ...

随机推荐

  1. Python—元类

    什么是元类? 元类是类的类,是类的模板 元类是用来控制如何创建类的,正如类是创建对象的模板一样,而元类的主要目的是为了控制类的创建行为 元类的实例化的结果为我们用class定义的类,正如类的实例为对象 ...

  2. 全局关键字搜索:Element UI Table内容过滤\jQuery过滤器fastLiveFilter插件\BootstrapVue插件;

    ```html data:{ resultMaster: [], otableData:[], schfilter:'' } watch: { schfilter: function(val, old ...

  3. Django 组件之 ----- content-type

    Django 组件之 content-type的使用 一个表和多个表进行关联,但具体随着业务的加深,表不断的增加,关联的数量不断的增加,怎么通过一开始通过表的设计后,不在后期在修改表,彻底的解决这个问 ...

  4. StackWalk64

    #include <Windows.h>   #define  PULONG_PTR ULONG** #define  PULONG ULONG* #define  ULONG_PTR U ...

  5. fiddler查看IP地址和请求响应时间

    (一)fiddler查看IP地址 1.点击菜单栏rules——customize rules… 2.ctrl+f搜索“static function main” 3.在main函数里加入下面一行代码, ...

  6. MySQL Limit优化(转)

    原文:http://bbs.landingbj.com/t-0-240894-1.html 首先,我们看一个分页SQL: SELECT time,pageFROM `l_not_200_page`WH ...

  7. Thread类相关方法

    线程对象 每一个线程都是和类Thread的实例相关联的.在Java中,有两种基本的使用Thread对象的方式,可用来创建并发性程序.  1.在应用程序需要发起异步任务的时候,只要生成一个Thread对 ...

  8. Junit概述

    Junit ->  java unit.也就是说Junit是xunit家族中的一员. unit   <- unit test case,即单元测试用例. Junit  = java uni ...

  9. web service 异常

    1.org/apache/commons/discovery/tools/DiscoverSingleton Exception in thread "main" java.lan ...

  10. C# 中那些常用的工具类(Utility Class)(三)

    今天来接着写这个系列的文章,这一篇主要是用来介绍关于C#中的XML序列化的问题,这个相信大家一定会经常使用它,特别是在WPF中,有时候我们需要将我们后台的数据保存在数据库中,从而在软件下一次启动的时候 ...