C. Watto and Mechanism
time limit per test

3 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

Watto, the owner of a spare parts store, has recently got an order for the mechanism that can process strings in a certain way. Initially the memory of the mechanism is filled with n strings. Then the mechanism should be able to process queries of the following type: "Given string s, determine if the memory of the mechanism contains string t that consists of the same number of characters as s and differs from s in exactly one position".

Watto has already compiled the mechanism, all that's left is to write a program for it and check it on the data consisting of n initial lines and m queries. He decided to entrust this job to you.

Input

The first line contains two non-negative numbers n and m (0 ≤ n ≤ 3·105, 0 ≤ m ≤ 3·105) — the number of the initial strings and the number of queries, respectively.

Next follow n non-empty strings that are uploaded to the memory of the mechanism.

Next follow m non-empty strings that are the queries to the mechanism.

The total length of lines in the input doesn't exceed 6·105. Each line consists only of letters 'a', 'b', 'c'.

Output

For each query print on a single line "YES" (without the quotes), if the memory of the mechanism contains the required string, otherwise print "NO" (without the quotes).

Examples
input

Copy
2 3
aaaaa
acacaca
aabaa
ccacacc
caaac
output

Copy
YES
NO
NO

暴力哈希  卡种子  CF出题人  就是强  HASH各种卡种子

  

 #include <bits/stdc++.h>
using namespace std;
typedef long long LL; const LL seed = ;
const LL mod = 1e9 + ;
const int maxn = 6e5 + ;
int n,m;
LL p[maxn];
char str[maxn];
set<LL>st;
void init(){
p[]=;
for (int i= ;i<maxn ;i++)
p[i]=p[i-]*seed%mod;
}
LL Hash(char s[]){
LL ret=;
for (int i= ; s[i] ;i++)
ret=(ret*seed+s[i])%mod;
return ret;
}
int check(char s[]){
LL h=Hash(s);
int len=strlen(s);
for (int i= ;i<len ;i++){
for (int j='a' ; j<='c' ;j++) {
if (j==s[i]) continue;
LL now=((((j-s[i])*p[len--i]%mod)+mod)+h)%mod;
if (st.find(now)!=st.end()) return ;
}
}
return ;
}
int main() {
scanf("%d%d", &n, &m);
init();
for (int i = ; i < n ; i++) {
scanf("%s", str);
st.insert(Hash(str));
}
for (int i = ; i < m ; i++) {
scanf("%s", str);
if (check(str)) printf("YES\n");
else printf("NO\n");
}
return ;
}

最新文章

  1. CentOS 7搭建SVN服务器
  2. 28 GroupSock(NetAddress)——live555源码阅读(四)网络
  3. Embed dll Files Within an exe (C# WinForms)—Winform 集成零散dll进exe的方法
  4. 直播开始:&#39;云榨汁机&#39;诞生记--聊聊JavaScript中的&#39;业务建模&#39;
  5. elementary os下anaconda的spyder.desktop文件
  6. KindEditor图片上传到七牛云
  7. Apache配置多端口多站点
  8. The 11th Zhejiang Provincial Collegiate Programming Contest-&gt;Problem A:A - Pokemon Master
  9. Scrapy入门程序点评
  10. 南阳师范学院ACM官方博客使用说明
  11. oracle和mysql几点差异对比
  12. WinSock 异步I/O模型
  13. 【Unity Shaders】Diffuse Shading——使用2D ramp texture来创建一个假的BRDF(双向反射分布函数)
  14. 《Python量化交易教程》第一部分新手入门 第1天:谁来给我讲讲Python?
  15. 学号 20175223 《Java程序设计》第 5 周学习总结
  16. Linux ansible 之 playbook
  17. Java 里如何实现线程间通信(转载)
  18. js 自定义类Android吐司提示框
  19. 暴雪《争霸艾泽拉斯》*采用自适应 SSAO
  20. swift3.0 自定义键盘

热门文章

  1. discuzX3.2 X3.4网站漏洞修复 SQL注入与请求伪造攻击利用与修复
  2. python2.7练习小例子(二十五)
  3. LeetCode:27. Remove Element(Easy)
  4. android去掉button默认的点击阴影
  5. linux里面的fork函数创建一个新进程
  6. .NET基础知识之七&mdash;&mdash;索引器
  7. Flexbox布局模式的理解
  8. QC的使用学习(三)
  9. BZOJ 4031 HEOI2015 小Z的房间 基尔霍夫矩阵+行列式+高斯消元 (附带行列式小结)
  10. 望岳物业APP开发过程