Prefix
南昌邀请赛的题,字典树
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll A[];
string s[];
ll trie[][];
ll v[];
ll tot=;
ll cnt[];
ll B[];
ll n,mod;
void insert(string s,int x)
{
int p=;
int len=s.length();
ll t=;
for(int i=;i<len;i++){
t=(t*A[s[i]-'a'])%mod;
if(trie[p][s[i]-'a']==){
trie[p][s[i]-'a']=++tot;
}
p=trie[p][s[i]-'a'];
cnt[p]++;
v[p]=t;
}
B[x]=t;
}
ll ans=;
void search(string s,int x)
{
int p=;
int len=s.length();
for(int i=;i<len;i++){
p=trie[p][s[i]-'a'];
if(v[p]>B[x]){
ans+=cnt[p];
}
}
}
int main()
{ scanf("%lld%lld",&n,&mod);
for(int i=;i<;i++){
scanf("%lld",&A[i]);
}
for(int i=;i<n;i++){
cin>>s[i];
insert(s[i],i);
}
for(int i=;i<n;i++){
search(s[i],i);
cout<<ans<<' ';
ans=;
} }
Prefix的更多相关文章
- Spring配置文件标签报错:The prefix "XXX" for element "XXX:XXX" is not bound. .
例如:The prefix "context" for element "context:annotation-config" is not bound. 这种 ...
- [LeetCode] Implement Trie (Prefix Tree) 实现字典树(前缀树)
Implement a trie with insert, search, and startsWith methods. Note:You may assume that all inputs ar ...
- [LeetCode] Longest Common Prefix 最长共同前缀
Write a function to find the longest common prefix string amongst an array of strings. 这道题让我们求一系列字符串 ...
- 1014: [JSOI2008]火星人prefix
1014: [JSOI2008]火星人prefix Time Limit: 10 Sec Memory Limit: 162 MB Description 火星人最近研究了一种操作:求一个字串两个后缀 ...
- [BZOJ1014][JSOI2008]火星人prefix
[BZOJ1014][JSOI2008]火星人prefix 试题描述 火星人最近研究了一种操作:求一个字串两个后缀的公共前缀.比方说,有这样一个字符串:madamimadam,我们将这个字符串的各个字 ...
- No plugin found for prefix 'mybatis-generator' in the current project
http://blog.csdn.net/you23hai45/article/details/50792430 1.错误描述 F:\workspaces\Mybatis>mvn mybatis ...
- 【leetcode】Longest Common Prefix
题目简述: Write a function to find the longest common prefix string amongst an array of strings. 解题思路: c ...
- LintCode 78:Longest Common Prefix
public class Solution { /** * @param strs: A list of strings * @return: The longest common prefix ...
- [LintCode] Longest Common Prefix 最长共同前缀
Given k strings, find the longest common prefix (LCP). Have you met this question in a real intervie ...
- BZOJ 1014: [JSOI2008]火星人prefix [splay 二分+hash] 【未完】
1014: [JSOI2008]火星人prefix Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 6243 Solved: 2007[Submit] ...
随机推荐
- java RMI 远程调用
1.背景 在学习代理模式的过程中接触到了远程调用,jdk有自己的RMI实现,所以这边自己实现了RMI远程调用,并记录下心得. 感受最深的是RMI和现在的微服务有点相似,都是通过"注册中心&q ...
- (转)http://blog.chinaunix.net/uid-8363656-id-2031644.html CGI 编写
第一章:基础的基础 回CGI教程目录 1.1 为什么使用CGI? 我没有把什么是CGI放在基础篇的第一段,是因为实在很难说明白到底什么是CGI.而如果你先知道CGI有什么作用,将会很好的理解CGI ...
- Log4net使用(二)
转:http://www.cnblogs.com/basilwang/archive/2006/06/09/421868.html Log4net同时按照日期和大小生成RollingFile和访问Sy ...
- oracle--对象权限
sys用户查询ww用户创建的表(已经commited) select * from ww.wwTable; 普通用户lisi查询ww用户的表 grant select on wwTable to li ...
- Java学习day10-面向对象特征之一:封装和隐藏
一.包package和引用import 1.关键字package package语句作为Java源文件的第一条语句,指明该文件中定义的类所在的包(若缺省该语句,则指定为无名包).包的存在是为了区别同名 ...
- Python库指南
Python库指南 1.time模块 作用:time模块是一个时间模块,与datetime模块它提供的功能是更加接近于操作系统层面. 应用场景:平时用的比较多的时间戳,等时间方面的操作,在爬虫方面经常 ...
- postgresql 口令: psql: 致命错误: 用户 认证失败
在Windows环境下使用psql 命令出现认证失败. 网上找了很多,都没讲到要点 D:\program\PostgreSql\bin>psql口令: psql: 致命错误: 用户 " ...
- 处理Chrome等浏览器无法上网,但QQ能正常使用问题
常见于安装VPN软件后导致的问题: 问题描述:QQ.微信客户端.等聊天工具可以聊天,但不能使用浏览器:打开网页失败:网络连接正常 问题解决步骤: 策略1: 打开网络和共享中心>>> ...
- 奇葩问题:Invalid bound statement (not found): cn.zss.zsdemo.mapper.RoleMapper.selectByPrimaryKey
使用mybatis,遇到Invalid bound statement (not found): cn.zss.zsdemo.mapper.RoleMapper.selectByPrimaryKey ...
- JS中兼容问题的汇总
获取非行内样式的兼容方式 function getStyle(obj,attr){ //获取非行间样式,obj是对象,attr是值 if(obj.currentStyle){ //针对ie获取非行间样 ...