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

歡迎訪問 生活随笔!

生活随笔

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

编程问答

BZOJ 4516: [Sdoi2016]生成魔咒 [后缀自动机]

發布時間:2023/12/9 编程问答 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 BZOJ 4516: [Sdoi2016]生成魔咒 [后缀自动机] 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

4516: [Sdoi2016]生成魔咒

題意:詢問一個字符串每個前綴有多少不同的子串


做了一下SDOI2016R1D2,題好水啊隨便AK

強行開map上SAM
每個狀態的貢獻就是\(Max(s)-Min(s)+1\)
插入的時候維護一下就行了

#include <iostream> #include <cstdio> #include <algorithm> #include <cstring> #include <cmath> #include <map> using namespace std; typedef long long ll; #define fir first #define sec second const int N=3e5+5, P=1e9+7; inline int read() {char c=getchar(); int x=0, f=1;while(c<'0' || c>'9') {if(c=='-')f=-1; c=getchar();}while(c>='0' && c<='9') {x=x*10+c-'0'; c=getchar();}return x*f; }int n, s[N]; ll ans; struct meow { map<int, int> ch; int par, val;}t[N]; int sz=1, root=1, last=1; void extend(int c) {int p=last, np=++sz;t[np].val = t[p].val+1;for(; p && !t[p].ch[c]; p=t[p].par) t[p].ch[c]=np;if(!p) t[np].par = root;else {int q=t[p].ch[c];if(t[q].val == t[p].val+1) t[np].par=q;else {ans -= t[q].val - t[p].val;int nq=++sz; t[nq]=t[q]; t[nq].val = t[p].val+1;t[q].par = t[np].par = nq;ans += t[q].val - t[nq].val; ans ++;for(; p && t[p].ch[c]==q; p=t[p].par) t[p].ch[c] = nq;}}ans+=t[np].val - t[t[np].par].val;last=np; } int main() {//freopen("in","r",stdin);freopen("incantation.in","r",stdin);freopen("incantation.out","w",stdout);n=read();for(int i=1; i<=n; i++) {s[i]=read();extend(s[i]);printf("%lld\n",ans);} }

轉載于:https://www.cnblogs.com/candy99/p/6652757.html

總結

以上是生活随笔為你收集整理的BZOJ 4516: [Sdoi2016]生成魔咒 [后缀自动机]的全部內容,希望文章能夠幫你解決所遇到的問題。

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