【CF472G】Design Tutorial 压位
题目大意
给出两个\(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 压位的更多相关文章
- cf 472G Design Tutorial: Increase the Constraints 分块+压位/FFT
题目大意 给出两个\(01\)序列\(A\)和\(B\) 哈明距离定义为两个长度相同的序列中,有多少个对应位置上的数字不一样 "00111" 和 "10101" ...
- 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 ...
- codevs 3119 高精度练习之大整数开根 (各种高精+压位)
/* codevs 3119 高精度练习之大整数开根 (各种高精+压位) 二分答案 然后高精判重 打了一个多小时..... 最后还超时了...压位就好了 测试点#1.in 结果:AC 内存使用量: 2 ...
- 压位加速-poj-2443-Set Operation
题目链接: http://poj.org/problem?id=2443 题目意思: 有n个集合(n<=1000),每个集合有m个数ai(m<=10000,1=<ai<=100 ...
- cf472D Design Tutorial: Inverse the Problem
D. Design Tutorial: Inverse the Problem time limit per test 2 seconds memory limit per test 256 mega ...
- cf472C Design Tutorial: Make It Nondeterministic
C. Design Tutorial: Make It Nondeterministic time limit per test 2 seconds memory limit per test 256 ...
- cf472B Design Tutorial: Learn from Life
B. Design Tutorial: Learn from Life time limit per test 1 second memory limit per test 256 megabytes ...
- cf472A Design Tutorial: Learn from Math
A. Design Tutorial: Learn from Math time limit per test 1 second memory limit per test 256 megabytes ...
- 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 ...
随机推荐
- Python—元类
什么是元类? 元类是类的类,是类的模板 元类是用来控制如何创建类的,正如类是创建对象的模板一样,而元类的主要目的是为了控制类的创建行为 元类的实例化的结果为我们用class定义的类,正如类的实例为对象 ...
- c++入门之内置数组和array比较
array是C++11中新提出来的容器类型,与内置数组相比,array是一种更容易使用,更加安全的数组类型,可以用来替代内置数组.作为数组的升级版,继承了数组最基本的特性,也融入了很多容器操作,下面介 ...
- spring实例入门
首先是bean文件: package onlyfun.caterpillar; public class HelloBean { private String helloWord = " ...
- Is-a
在知识表示.面向对象程序设计与面向对象设计的领域里, is-a(英语:subsumption,包含架构)指的是类的父子继承关系, 例如类D是另一个类B的子类(类B是类D的父类). 换句话说,通常&qu ...
- CentOS7 修改MAC地址
CentOS7 修改MAC地址 - mixboot - CSDN博客https://blog.csdn.net/u010953692/article/details/79650522
- centos 6.5 查看时区和设置时区
centos6.x 和centos7.x在时区方面有点差距,本文是针对centos6.x进行介绍. 其实在我的一个博文里,在安装系统的时候就可以进行时区的设置,本文介绍的是用命令进行时区查看和设置. ...
- Spring Boot+Jsp启动异常
No Java compiler available for configuration options compilerClassName 加入maven配置 <dependency> ...
- java中级——集合框架【1】-ArrayList
集合框架----ArrayList 引子:我们先来看看传统数组的用法 写一个Hero对象类 package cn.jse.t1; public class Hero { public String n ...
- layer弹层基本参数初尝试
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...
- E: Unable to correct problems, you have held broken packages
问题: apt install libmysqlclient-dev Reading package lists... DoneBuilding dependency tree Readi ...