【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 ...
随机推荐
- 网络拓扑自动发掘之三层设备惯用的SNMP OID的含义
原文地址:https://blog.csdn.net/maty_wang/article/details/81305070 1. ipNetToMediaIfIndex Name/OID: ipNet ...
- 深度学习之概述(Overview)
2016年被称为人工智能的元年,2017年是人能智能应用的元年:深度学习技术和应用取得飞速发展:深度学习在互联网教育场景也得到广泛应用.本文主要介绍机器学习及深度学习之定义及基本概念.相关网络结构等. ...
- TCP粘包问题解析与解决
一.粘包分析 作者本人在写一个FTP项目时,在文件的上传下载模块遇到了粘包问题.在网上找了一些解决办法,感觉对我情况都不好用,因此自己想了个比较好的解决办法,提供参考 1.1 粘包现象 在客户端与服务 ...
- mysql 中Varchar 与char的区别
一.字符与字节与编码关系 ASCII码中,一个英文字母(不分大小写)占一个字节的空间,一个中文汉字占两个字节的空间.一个二进制数字序列,在计算机中作为一个数字单元,一般为8位二进制数,换算为十进制.最 ...
- winform自定义控件开发
1.添加控件属性 //添加私有的控件属性 private string djm;//单据名 //添加属性描述 [Browsable(true)] [Description("djm" ...
- opencv2\core\cuda.hpp(106): error C2059: 语法错误:“常量”
在 cuda.hpp 中, virtual void free(GpuMat* mat) = 0; -> virtual void _free(GpuMat* mat) = 0;
- [转帖]FORFILES 的简单介绍。
FORFILES https://blog.csdn.net/sandy9919/article/details/82932460 命令格式: forfiles.exe /p "D:\备份& ...
- 【学亮开讲】Oracle内外连接查询20181119
--内连接查询 --需求:查询显示业主编号.业主名称.业主类型名称 select os.id 业主编号,os.name 业主名称,ot.name 业主类型名称 from t_owners os,t_o ...
- 【学亮IT手记】jQuery each()函数用法实例
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <script sr ...
- Freemarker 页面静态化技术使用入门案例
在访问 新闻.活动.商品 详情页面时, 路径可以是 xx[id].html, 服务器端根据请求 id, 动态生成 html 网页,下次访问数据时,无需再查询数据,直接将 html 静态页面返回.这样一 ...