题干:

yah has n strings <s1​,⋯,sn​>, and he generates a sequence P by two steps:

P=<s1​,⋯,sn​>
Replace each si​ with all prefixes of itself.
An example is:

the n strings are < aab,ab >
first, P =< aab,ab >
then, P =< a,aa,aab,a,ab >
There are 26 positive integers d1​,⋯,d26​ that denote the difficulty to identify lowercase English letter a,b,⋯,z for yah.

The difficulty to identify a string strstr is (i=1∏∣str∣​dstri​​) mod  m

Now, yah wants to calculate: for each string si​(i=1,⋯,n), the number of strings in P that is prefix of si ​and more difficult than si​.

Input
The first line contains two integers n,mn,m(1≤n≤105,1≤m≤2×105).

The second line contains 26 positive d1​,⋯,d26​, 0^50≤di​≤105.

The following n lines, each line contains a string, the ith​ lines contains si​, the sum of length of all strings is not great than 2×105.

Output
The only line contains n integers, the ith​ integer denoting the number of strings in P that is prefix of si​ but more difficult to identify for yah.

题意:
给定n代表n个字符串,m代表模数,再给定26个字母的每个字母的权值d,再定义字符串s的值:前i个字符对应的子串的值dd[i]= dd[i-1]*(d[s[i]])  %  m 。

输入n个字符串,求对于每个字符串,大于该字符串 的 值 的 前缀的 个数(值dd[i]= dd[i-1]*(d[s[i]])  %  m ),主要求前缀的个数

解题报告:

map暴力搞一搞就能过、、但是要真是比赛场还是老老实实写hash吧、、万一T了呢。

其实也可以字典树,存前缀出现的次数。也不难想。

AC代码:

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<queue>
#include<stack>
#include<map>
#include<vector>
#include<set>
#include<string>
#include<cmath>
#include<cstring>
#define FF first
#define SS second
#define ll long long
#define pb push_back
#define pm make_pair
using namespace std;
typedef pair<int,int> PII;
const int MAX = 2e5 + 5;
map<string,PII> mp;
int n;
int d[MAX];
ll m;
string s[MAX],tmp;
int main()
{ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);cin>>n>>m;for(int i = 0; i<26; i++) cin>>d[i];for(int i = 1; i<=n; i++) {cin>>s[i];tmp = "";int len = s[i].length();ll tmpp = 1;for(int j = 0; j<len; j++) {tmp += s[i][j];tmpp *= d[s[i][j]-'a'];tmpp %= m;auto it = mp.find(tmp);if(it == mp.end()) mp[tmp] = pm(tmpp,1);else mp[tmp].SS ++;} }for(int i = 1; i<=n; i++) {tmp = "";int ans = 0;int tar = mp[s[i]].FF;int len = s[i].length();for(int j = 0; j<len; j++) {tmp += s[i][j];if(mp[tmp].FF > tar) ans += mp[tmp].SS;}cout << ans ;if(i == n) cout << "\n";else cout << " ";//printf("%d%c",ans,i == n ?'\n' :' ');}return 0 ;
}

【2019南昌邀请赛现场赛 - J】Prefix(STLmap,思维)相关推荐

  1. 【2019南昌邀请赛现场赛 - G】Winner(建图,tarjan缩点 或 贪心)

    题目大意: n个人参加竞技比赛.比赛由三种模式a,b,c,每个人在每种模式下有对应的权值a[i]b[i]c[i].举行n−1场比赛,每场比赛主办方可以选择两个人决斗,能力值低的人淘汰.这样保证n-1场 ...

  2. 【2019南昌邀请赛现场赛 - G】Winner(思维、图论+缩点)

    题目链接: https://nanti.jisuanke.com/t/40259" Ichuan really likes to play games, so he organized a ...

  3. 【计蒜客 - 2019南昌邀请赛网络赛 - I】Max answer(单调栈,RMQ)

    题干: Alice has a magic array. She suggests that the value of a interval is equal to the sum of the va ...

  4. 【计蒜客 - 2019南昌邀请赛网络赛 - M】Subsequence(字典树,dp预处理)

    题干: Give a string SS and NN string T_iTi​ , determine whether T_iTi​ is a subsequence of SS. If ti i ...

  5. 【计蒜客 - 2019南昌邀请赛网络赛 - K】MORE XOR(数学,找规律,打表)

    Given a sequence of nn numbers a_1, a_2, \cdots, a_na1​,a2​,⋯,an​ and three functions. Define a func ...

  6. 2019南昌邀请赛网络赛

      A. PERFECT NUMBER PROBLEM 这题没什么要说的. #include<bits/stdc++.h>using namespace std;int main(){co ...

  7. 【计蒜客 - 2019南昌邀请赛网络赛 - H】Coloring Game(找规律,思维dp)

    题干: David has a white board with 2 \times N2×N grids.He decides to paint some grids black with his b ...

  8. 2019 ICPC 徐州网络赛 J.Random Access Iterator

    2019 ICPC 徐州网络赛 J.Random Access Iterator 题目大意:给你n个点和n-1条边(树形结构),保证1为根节点,通过以下方式dfs遍历: 询问dfs到最深节点的概率(有 ...

  9. 2019 ICPC南昌邀请赛网络赛比赛过程及题解

    解题过程 中午吃饭比较晚,到机房lfw开始发各队的账号密码,byf开始读D题,shl电脑卡的要死,启动中...然后听到谁说A题过了好多,然后shl让blf读A题,A题blf一下就A了.然后lfw读完M ...

最新文章

  1. 如何快速出稿一个优秀APP的构图
  2. linux下源码安装rabbitMq
  3. Nginx-Nginx配置文件详细说明
  4. ssh作业批改系统_如何看待「全国至少十省份叫停家长批改作业」?能否从根源解决问题?...
  5. 从中师到博士,我用了22年...
  6. 云云协同解决方案全景图发布 华为云助力科技企业云上创新
  7. 英特尔显示器音频_骁龙865、全球最快32寸显示器、高达联名路由……这场发布会为电竞玩家带来多少高科技?...
  8. 计算机原理课 如何在中小学课堂中变成有趣,在课堂中如何发挥电教辅助教学优势...
  9. wmsys.wm_concat的几个用法
  10. 两个rpm文件包存在互相依赖关系时,需要同时安装,解决办法如下
  11. C语言指针详解(通俗易懂)
  12. 基于实现韦尔奇·鲍威尔法对图进行着色
  13. 知识竞赛软件已全面取代了传统手工赛场控制方式
  14. 在打开 Office XP 或 Office 2003 文档时,会提示您为 ActiveX 控件授予权限
  15. android手机无法root成功,安卓手机不能ROOT怎么办
  16. 西安电子科技大学计算机本校好考吗,西安电子科技大学:除了计算机和通信工程,这些专业高考也很热门...
  17. Type number trivially inferred from a number literal, remove type annotation.
  18. 精通Groovy_B 循环, 范围, 集合, 映射, 闭包, 类, UT
  19. 零跑坚持自主研发,探索数字时代的驾驶体验
  20. leetcode 881 救生艇 (python3- 贪心算法)

热门文章

  1. ADO.NET Entity Framework 使用中的经验总结
  2. 740. Delete and Earn
  3. 【数据结构与算法】排序优化
  4. [Leedcode][JAVA][第105题][从前序与中序遍历序列构造二叉树][栈][递归][二叉树]
  5. java 并发 主键_高并发数据库自增主键分析
  6. python单元测试的应用_单元测试pythongui应用程序的推荐方法是什么?
  7. python群发短信脚本_python实现zabbix发送短信脚本
  8. android 组件化_Android 组件化路由框架设计(仿Arouter)
  9. openwrt 格式化_OPENWRT扩展系统到U盘
  10. mysql.w002_mysql简单例子