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

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

【bzoj4084】[Sdoi2015]bigyration hash

發(fā)布時(shí)間:2023/12/8 编程问答 34 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【bzoj4084】[Sdoi2015]bigyration hash 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

bzoj沒有題面,題面在vijos。


所以說讀入char再丟給string并不會(huì)慢…

短串扔到hash表里。
長串的前半部分復(fù)制一份,然后在上面跑,若長串的后半部分出現(xiàn)過,則答案加上后面的hash值的出現(xiàn)次數(shù)。

寫了雙hash+掛鏈表,因?yàn)閷懥酥羔?#xff0c;并且雙hash常數(shù)大,所以TLE+MLE,還有莫名其妙的WA…………

自然溢出+map在vijos上就是過不了……T兩個(gè)點(diǎn),不過在bzoj還是能A的。

看題解有人寫的在bool數(shù)組中若已被占用則往后跳…在bzoj實(shí)測表現(xiàn)和map差不多…vijos也是T兩個(gè)點(diǎn)…

#include<cstdio> #include<cstring> #include<iostream> #include<algorithm> #include<map> using namespace std;typedef unsigned long long ULL; typedef long long LL; const int SZ = 4000010; const int base = 13331;string S1[SZ],S2[SZ];map<ULL,int> h;ULL hash[SZ],mi[SZ];ULL gethash(string s) {ULL ans = 0;for(int i = 0;i < s.length();i ++)ans = ans * base + s[i] - 'a' + 1;return ans; }ULL getstr(int l,int r) {int len = r - l + 1;return hash[r] - hash[l - 1] * mi[len]; }char s[SZ];void read(char s[]) {memset(s,0,sizeof(s));int tot = 0;char a = getchar();for(;a < 'a' || a > 'z';a = getchar());for(;a >= 'a' && a <= 'z';a = getchar())s[tot ++] = a; }int main() {int n,m,len1,len2;scanf("%d%d%d%d",&n,&m,&len1,&len2);mi[0] = 1;for(int i = 1;i <= len1 + len2;i ++)mi[i] = mi[i - 1] * base;for(int i = 1;i <= n;i ++)read(s),S1[i] = s;for(int i = 1;i <= m;i ++)read(s),S2[i] = s;if(len1 < len2) swap(S1,S2),swap(n,m),swap(len1,len2);for(int i = 1;i <= m;i ++)h[gethash(S2[i])] ++;int len = (len1 + len2) >> 1;LL ans = 0;for(int i = 1;i <= n;i ++){for(int j = 0;j < len * 2;j ++)hash[j + 1] = hash[j] * base + S1[i][j % len] - 'a' + 1;ULL x = 0;for(int j = len;j < len1;j ++)x = x * base + S1[i][j] - 'a' + 1;for(int j = 1;j <= len;j ++){ULL y = getstr(j,j + len1 - len - 1);if(x == y){ULL a = getstr(j + len1 - len,j + len - 1);ans += h[a];}}}printf("%lld\n",ans);return 0; }

總結(jié)

以上是生活随笔為你收集整理的【bzoj4084】[Sdoi2015]bigyration hash的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。