Test instructions: To give you multiple numbers of strings, to find essentially different substrings and (minus the preamble 0)
Puzzle: Build a broad-based Sam, just started to think is to use L to calculate, found that the impact of the leading 0 on L can not be eliminated, so will not do = =, the original should be directly with a new array to the current number of substrings is good
#pragma gcc optimize (2)//#pragma gcc optimize (3)//#pragma gcc optimize (4)//#pragma gcc optimize ("unroll-loops")//# pragma comment (linker, "/stack:200000000")//#pragma gcc optimize ("ofast,no-stack-protector")//#pragma gcc target (" Sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native ") #include <bits/stdc++.h> #define FI first#define SE Second#define DB Double#define mp make_pair#define pb push_back#define Pi ACOs ( -1.0) #define LL long Long#define VI vector& lt;int> #define MOD 2012#define ld long double#define C 0.5772156649#define ls l,m,rt<<1#define rs M+1,R,RT<&L T;1|1#define PLL pair<ll,ll> #define PIL pair<int,ll> #define PLI pair<ll,int> #define PII pair<int, int>//#define CD complex<double> #define ULL unsigned long long#define base 1000000000000000000#define Max (A, B) ((a) > (b)? (a):(B) #define MIN (a) < (b) ( A):(B)) #define FIN freopen ("A.txt", "R", stdin) #define Fout freopen ("C.txt", "w", stdout) #define FIO Ios::sync_with_ Stdio (false); cIn.tie (0) template<typename t>inline t const& MAX (T const &a,t const &B) {return a>b?a:b;} Template<typename t>inline T const& MIN (T const &a,t const &B) {return a<b?a:b;} inline void Add (ll &a,ll b) {a+=b;if (a>=mod) A-=mod;} inline void Sub (ll &a,ll b) {a-=b;if (a<0) A+=mod;} inline ll gcd (ll A,ll b) {return B?GCD (b,a%b): A;} inline ll QP (ll A,ll b) {ll ans=1;while (b) {if (b&1) ans=ans*a%mod;a=a*a%mod,b>>=1;} return ans;} inline ll QP (ll a,ll b,ll c) {ll ans=1;while (b) {if (b&1) ans=ans*a%c;a=a*a%c,b>>=1;} return ans;} Using namespace Std;const double eps=1e-8;const ll Inf=0x3f3f3f3f3f3f3f3f;const int n=100000+10,maxn=100000+10,inf= 0x3f3f3f3f;char s[n];struct sam{int last,cnt; int ch[n<<1][10],fa[n<<1],l[n<<1],c[n<<1]; int a[n<<1],num[n<<1],sum[n<<1]; void Init () {cnt=1; } void ins (int x) {if (ch[last][x]) {int p=last,q=ch[last][x]; if (l[q]==l[p]+1) last=q; else {int nq=++cnt;l[nq]=l[p]+1; memcpy (ch[nq],ch[q],sizeof ch[q]); FA[NQ]=FA[Q];FA[Q]=LAST=NQ; for (; ch[p][x]==q;p=fa[p]) ch[p][x]=nq; } return; } int p=last,np=++cnt;last=np;l[np]=l[p]+1; For (;p &&!ch[p][x];p =fa[p]) CH[P][X]=NP; if (!p) fa[np]=1; else {int q=ch[p][x]; if (l[q]==l[p]+1) fa[np]=q; else {int nq=++cnt;l[nq]=l[p]+1; memcpy (ch[nq],ch[q],sizeof ch[q]); FA[NQ]=FA[Q];FA[Q]=FA[NP]=NQ; for (; ch[p][x]==q;p=fa[p]) ch[p][x]=nq; }}} void Topo () {for (int i=1;i<=cnt;i++) c[l[i]]++; for (int i=1;i<=cnt;i++) c[i]+=c[i-1]; for (int i=1;i<=cnt;i++) a[c[l[i]]--]=i; } void Build () {last=1; int Len=strlen (s+1); for (int i=1;i<=len;i++) ins (s[i]-' 0 '); } void Cal () {topo (); Num[1]=1; for (int i=1;i<=cnt;i++) {int p=a[i]; for (int j=0;j<10;j++) if (Ch[p][j]) {if (i==1&&j==0) continue; NUM[CH[P][J]]+=NUM[P]; Sum[ch[p][j]]= (sum[ch[p][j]]+ (sum[p]*10+num[p]*j)%mod)%mod; }} int ans=0; for (int i=1;i<=cnt;i++) ans= (ans+sum[i])%mod; printf ("%d\n", ans); for (int i=0;i<=cnt;i++) {for (int j=0;j<10;j++) ch[i][j]=0; sum[i]=fa[i]=num[i]=a[i]=c[i]=l[i]=0; }}}sam;int Main () {//fin; int n; while (~SCANF ("%d", &n)) {sam.init (); for (int i=0;i<n;i++) {scanf ("%s", s+1); Sam.build (); } sam.cal (); } return 0;} /********************3120120012********************/
Hdu-4436sam Nude Questions