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的更多相关文章

  1. Spring配置文件标签报错:The prefix "XXX" for element "XXX:XXX" is not bound. .

    例如:The prefix "context" for element "context:annotation-config" is not bound. 这种 ...

  2. [LeetCode] Implement Trie (Prefix Tree) 实现字典树(前缀树)

    Implement a trie with insert, search, and startsWith methods. Note:You may assume that all inputs ar ...

  3. [LeetCode] Longest Common Prefix 最长共同前缀

    Write a function to find the longest common prefix string amongst an array of strings. 这道题让我们求一系列字符串 ...

  4. 1014: [JSOI2008]火星人prefix

    1014: [JSOI2008]火星人prefix Time Limit: 10 Sec Memory Limit: 162 MB Description 火星人最近研究了一种操作:求一个字串两个后缀 ...

  5. [BZOJ1014][JSOI2008]火星人prefix

    [BZOJ1014][JSOI2008]火星人prefix 试题描述 火星人最近研究了一种操作:求一个字串两个后缀的公共前缀.比方说,有这样一个字符串:madamimadam,我们将这个字符串的各个字 ...

  6. 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 ...

  7. 【leetcode】Longest Common Prefix

    题目简述: Write a function to find the longest common prefix string amongst an array of strings. 解题思路: c ...

  8. LintCode 78:Longest Common Prefix

      public class Solution { /** * @param strs: A list of strings * @return: The longest common prefix ...

  9. [LintCode] Longest Common Prefix 最长共同前缀

    Given k strings, find the longest common prefix (LCP). Have you met this question in a real intervie ...

  10. BZOJ 1014: [JSOI2008]火星人prefix [splay 二分+hash] 【未完】

    1014: [JSOI2008]火星人prefix Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 6243  Solved: 2007[Submit] ...

随机推荐

  1. 安全运维 - Windows系统攻击回溯

    Windows应急事件 病毒.木马.蠕虫 Web服务器入侵事件或第三方服务入侵事件 系统入侵事件 网络攻击事件(DDOS.ARP.DNS劫持等) 通用排查思路 获知异常事件基本情况 发现主机异常现象的 ...

  2. mooc-IDEA 收藏位置和文件--003

    六.IntelliJ IDEA -收藏位置和文件(类/函数) 1.收藏自己喜欢的文件---代码 添加一个Favorites列表 定义名称 Help->Find Action... 选择Add t ...

  3. 知识点C++

    比较2个字符串的大小…… s1=s2,strcmp(s1,s2) == ; s1>s2, strcmp(s1,s2) == ; s1<s2, strcmp(s1,s2) == -; str ...

  4. 15 (H5*) JS第5天 对象

    目录 1:创建对象 2:工厂模式创建对象 3:自定义构造函数创建对象 4:自定义构造函数做了那些事情 5:字面量方式创建对象:一次性对象 6:对象总结 7:json数据类型 8:简单数据类型和复杂数据 ...

  5. idea / eclipse 批量 替换 空白行

    1.选择Regular expression项,允许查询匹配正则表达式 2.在Find文本框输入正则表达式:^\s*\n   , 点击ReplaceAll 转移字符 含义 ^ 否 * 0个或多个 \s ...

  6. WOJ#2423 安全出行Safe Travel

    描述 精灵最近在农场上泛滥,它们经常会阻止牛们从农庄(牛棚_1)走到别的牛棚(牛_i的目的 地是牛棚_i).每一个精灵只认识牛_i并且知道牛_i一般走到牛棚_i的最短路经.所以它们在牛_i到牛棚_i之 ...

  7. Excel VBA批量处理寸照名字

    需求:因为处理学生学籍照片,从照相馆拿回来的寸照是按班级整理好,文件名是相机编号的文件.那么处理的话,是这么一个思路,通过Excel表格打印出各班A4照片列表,让学生自行填上照片对应姓名.表格收回来后 ...

  8. 靶形数独 (dfs+预处理+状态压缩)

    #2591. 「NOIP2009」靶形数独 [题目描述] 小城和小华都是热爱数学的好学生,最近,他们不约而同地迷上了数独游戏,好胜的他们想用数独来一比高低.但普通的数独对他们来说都过于简单了,于是他们 ...

  9. vscode加MinGw三步搭建c/c++调试环境

    vscode加MinGw三步搭建c/c++调试环境 step1:安装vscode.MinGw 1.1 vscod常规安装:https://code.visualstudio.com/ 1.2 MinG ...

  10. Ubuntu中找不到pip3命令的解决方法

    Ubuntu中找不到pip3命令的解决方法 Ubuntu 有 python2 和 python3. 今天使用 Ubuntu 中的 python3 时,想要安装第三方库却发现 pip 指向的是 pyth ...