日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

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

發布時間:2023/12/10 编程问答 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【2019南昌邀请赛现场赛 - J】Prefix(STLmap,思维) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

題干:

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

P=<s1?,?,sn?>
Replace each?si??with all pre?xes of itself.
An example is:

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

The di?culty 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 pre?x of si ?and more di?cult than si?.

Input
The ?rst 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 pre?x of si??but more di?cult 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,思维)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。