【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 ...
随机推荐
- 01-HTML介绍
1.WEB标准 web准备介绍: w3c:万维网联盟组织,用来制定web标准的机构(组织) web标准:制作网页遵循的规范 web准备规范的分类:结构标准.表现标准.行为标准. 结构:html.表示: ...
- 牛客国庆集训派对Day2
题目链接:https://www.nowcoder.com/acm/contest/202/A A 题意:给出最大4096*64和64*4096的矩阵,其中有一个矩阵只含有0和1,问你它们相乘所得到得 ...
- 本地项目托管到github上
一,步骤 1.在github上新建一个仓库 2.进入我的项目目录, git init //初始化本地仓库 3.git add . //把修改的代码提交到暂存区 4.git status 该命令会把你本 ...
- react双组件传值和传参
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- C#复习笔记(4)--C#3:革新写代码的方式(用智能的编译器来防错)
用智能的编译器来防错 本章的主要内容: 自动实现的属性:编写由字段直接支持的简单属性, 不再显得臃肿不堪: 隐式类型的局部变量:根据初始值推断类型,简化局部变量的声明: 对象和集合初始化程序:用一个表 ...
- C#复习笔记(2)--C#1所搭建的核心基础
通过对C#1所搭建的核心基础的深入了解,可以知道之后的C#版本在C#1的基础上做了很多扩展,而这些扩展都是基于C#搭建的核心基础而来的. 委托 一.编写委托的过程 委托经常和C语言的“函数指针”挂钩. ...
- 1 Servlet 简介
1 Servlet是sun公司提供的一门用于开发动态web资源的技术.用户若用Java技术开发一个动态web资源或者网页,需要完成以下2个步骤:① 编写一个Java类,实现servlet接口② 把开发 ...
- [转帖]Ipvsadm参数详解(常用命令)
Ipvsadm参数详解(常用命令) 2013年11月29日 12:41:40 怀素1980 阅读数:15901 版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.cs ...
- LLDB 3.9.1 安装方法
1. baidu到一个安装方法 进行尝试: 来源: https://zhuanlan.zhihu.com/p/40780819https://www.jianshu.com/p/f965bbba6eb ...
- Spring boot+ logback环境下,日志存放路径未定义的问题
日志路径未定义 环境:Spring boot + logback 配置文件: <configuration> <springProfile name="dev"& ...