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] ...
随机推荐
- Python 爬取淘宝商品数据挖掘分析实战
Python 爬取淘宝商品数据挖掘分析实战 项目内容 本案例选择>> 商品类目:沙发: 数量:共100页 4400个商品: 筛选条件:天猫.销量从高到低.价格500元以上. 爬取淘宝商品 ...
- Linux pip命令报错 -bash: pip: command not found
下载 $ wget https://bootstrap.pypa.io/get-pip.py 安装 $ python get-pip.py 查看版本 $ pip -V 查看安装路径: find / - ...
- css 实现渐变
background:-ms-radial-gradient(circle,rgba(0, 0, 0, 0.2),rgba(0,0,0,0)); /* IE 10*/ background: -web ...
- LeNet-5详解
一.前言 LeNet-5出自论文Gradient-Based Learning Applied to Document Recognition,是一种用于手写体字符识别的非常高效的卷积神经网络. 本文 ...
- MySQL基础和习题强化(完结)
Mysql 1. Mysql基础知识 1.1. Index and table searching of Mysql 1.1.1. Basic concepts of Mysq ...
- spring源码下载及转入ECLIPSE
转自:https://www.cnblogs.com/scevecn/p/6043284.html 本例spring源码版本是4.3.0的, 所以jdk需要准备1.8的(不同版本源码要求的jdk不一样 ...
- [19/05/05-星期日] JDBC(Java DataBase Connectivity,java数据库连接)_mysql基本知识
一.概念 (1).是一种开放源代码的关系型数据库管理系统(RDBMS,Relational Database Management System):目前有很多大公司(新浪.京东.阿里)使用: (2). ...
- (4.30)全面了解触发器:DML、DDL、LOGON触发器
DML.DDL.LOGON触发器 转自:https://www.cnblogs.com/seusoftware/p/9120632.html 触发器可以理解为由特定事件触发的存储过程, 和存储过程.函 ...
- package.json说明
package.json是什么? 直接的说:就是管理你本地安装的npm包 一个package.json文件可以做如下事情: 展示项目所依赖的npm包 允许你指定一个包的版本[范围] 让你建立起稳定,意 ...
- C# Lodop与C-Lopdop选择打印机
原文:https://www.cnblogs.com/huaxie/p/9766886.html https://www.cnblogs.com/huaxie/p/10857490.html http ...