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

歡迎訪問 生活随笔!

生活随笔

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

编程问答

bzoj2754: [SCOI2012]喵星球上的点名

發布時間:2024/4/17 编程问答 22 豆豆
生活随笔 收集整理的這篇文章主要介紹了 bzoj2754: [SCOI2012]喵星球上的点名 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

傳送門

事實證明,我肉眼debug了兩個晚上,還是不及對拍效率高。

AC自動機寫錯了都毫不自覺的智障宸

因為數據水,寫的暴力

?

//Achen #include<algorithm> #include<iostream> #include<cstring> #include<cstdlib> #include<vector> #include<cstdio> #include<queue> #include<cmath> #include<map> #define For(i,a,b) for(int i=(a);i<=(b);i++) #define Rep(i,a,b) for(int i=(a);i>=(b);i--) const int N=400007; typedef long long LL; using namespace std; int n,m,a[N],ll[N],rr[N],ans2[N],cnt[N];template<typename T>void read(T &x) {char ch=getchar(); x=0; T f=1;while(ch!='-'&&(ch<'0'||ch>'9')) ch=getchar();if(ch=='-') f=-1,ch=getchar();for(;ch>='0'&&ch<='9';ch=getchar()) x=x*10+ch-'0'; x*=f; }map<int,int>ch[N]; #define IT map<int,int>::iterator int tot,rt,w[N],fail[N],ans[N]; void insert(int ql,int qr) {if(!rt) rt=++tot;int x=rt;For(i,ql,qr) {int c=a[i];if(!ch[x][c]) ch[x][c]=++tot;x=ch[x][c];} w[x]++; }queue<int>que; void get_fail() {que.push(rt);while(!que.empty()) {int x=que.front();que.pop();for(IT it=ch[x].begin();it!=ch[x].end();it++) {int y=it->second;if(x==rt) fail[y]=rt;else {int z=fail[x];for(;fail[z]&&!ch[z][it->first];z=fail[z]);if(ch[z][it->first]) fail[y]=ch[z][it->first];else fail[y]=rt;}que.push(y); }} }#define pr pair<int,int> pr sta[N]; int top; int qry(int ql,int qr) {int x=rt,rs=0;For(i,ql,qr) {int c=a[i];for(;fail[x]&&!ch[x][c];x=fail[x]);if(ch[x][c]) {x=ch[x][c]; if(w[x]) {rs+=w[x]; cnt[x]++;sta[++top]=make_pair(x,w[x]);w[x]=0; }int y=fail[x];while(w[y]) {rs+=w[y];sta[++top]=make_pair(y,w[y]);w[y]=0; cnt[y]++;y=fail[y];}}}while(top) {pr tp=sta[top--];w[tp.first]=tp.second;}return rs; } void calc(int ql,int qr) {int x=rt;For(i,ql,qr) {int c=a[i];x=ch[x][c];}printf("%d\n",cnt[x]); }//#define DEBUG int main() { #ifdef DEBUGfreopen("2754.in","r",stdin);freopen("2754.out","w",stdout); #endifread(n); read(m);For(i,1,n) {int len; read(len);ll[i]=a[0]+1;For(j,1,len) read(a[++a[0]]);a[++a[0]]=-1;read(len);For(j,1,len) read(a[++a[0]]);rr[i]=a[0];}For(i,1,m) {int len; read(len);ll[n+i]=a[0]+1;For(j,1,len) read(a[++a[0]]);rr[n+i]=a[0];insert(ll[n+i],rr[n+i]);}get_fail();For(i,1,n) ans[i]=qry(ll[i],rr[i]);For(i,1,m)calc(ll[n+i],rr[n+i]);For(i,1,n-1) printf("%d ",ans[i]);printf("%d",ans[n]);return 0; } /* 4 1 1 2 1 2 4 3 1 1 9 6 6 9 1 10 7 9 4 8 1 9 9 6 9 9 7 9 3 10 6 8 9 2 1 1 4 1 4 1 9 5 8 9 1 5 2 4 2 10 7 6 2 5 1 */ View Code

?

轉載于:https://www.cnblogs.com/Achenchen/p/8561793.html

總結

以上是生活随笔為你收集整理的bzoj2754: [SCOI2012]喵星球上的点名的全部內容,希望文章能夠幫你解決所遇到的問題。

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