HDU - 4436sam裸题
题意:给你多个数字串,求本质不同的子串和(去掉前导零)
题解:建广义sam,刚开始一直想的是用l来计算,发现前导零对l的影响根本消不掉,所以不会做= =,原来应该是直接用一个新的数组表示到当前有多少个子串就好了
//#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<int>
#define mod 2012
#define ld long double
#define C 0.5772156649
#define ls l,m,rt<<1
#define rs m+1,r,rt<<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)?(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;
}
/********************
3
12
012
0012
********************/
HDU - 4436sam裸题的更多相关文章
- hdu 1711kmp裸题
#include<stdio.h> #define N 1000050 int text[N],t[N],next[N],n,m; void getnext() { int j=0,k=- ...
- HDU 1102 最小生成树裸题,kruskal,prim
1.HDU 1102 Constructing Roads 最小生成树 2.总结: 题意:修路,裸题 (1)kruskal //kruskal #include<iostream> ...
- HDU 1248 寒冰王座(完全背包裸题)
寒冰王座 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submi ...
- HDU 2602 Bone Collector(01背包裸题)
Bone Collector Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) T ...
- HDU 1711 Number Sequence(KMP裸题,板子题,有坑点)
Number Sequence Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- hdu Flow Problem (最大流 裸题)
最大流裸题,贴下模版 view code#include <iostream> #include <cstdio> #include <cstring> #incl ...
- hdu_3966_Aragorn's Story(树链剖分裸题)
题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=3966 题意:给你一棵树,然后给定点之间的路径权值修改,最后单点查询 题解:树链剖分裸题,这里我用树状数 ...
- hdu-2602&&POJ-3624---01背包裸题
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=2602 https://vjudge.net/problem/POJ-3624 都是01背包的裸题 这 ...
- 13-Oulipo(kmp裸题)
http://acm.hdu.edu.cn/showproblem.php?pid=1686 Oulipo Time Limit: 3000/1000 MS (Java/Others) Memo ...
随机推荐
- Vue内置的Component标签用于动态切换组件
html <div id="app"> <component :is="cut"></component> <butt ...
- [bootstrapValidator] - bootstrap的验证工具
翻了下之前和同事做的一个验证 <!--bootstrapValidator--> <script type="text/javascript" th:inline ...
- Thymeleaf 模板引擎技术
引入Thymeleaf: <!DOCTYPE html> <html lang="en" xmlns:th="http://www.thymeleaf. ...
- 前端分页插件bootstrapPaginator的使用
引入bootstrap-paginator.js <table class="table table-striped table-bordered table-hover dataT ...
- onpause 与 onresume
- python类的成员
一.实例变量:简单的来说就是给对象赋值 class Person: def __init__(self, name, card_no, height, weight, address, laopo): ...
- R语言网页爬虫
R 是统计计算和数据分析的利器.给定一个数据集,利用前几章介绍到的 R 中灵活的数据结构或高性能计算,我们可以很方便地进行数据转换.建模和数值分析.一般来说,商业数据库会将数据以表格的形式很好地组织起 ...
- 关于fstream、ifstream、ofstream读写文本文件、二进制文件详解
fstream.ifstream.ofstream是c++中关于文件操作的三个类 fstream类对文件进行读操作和写操作 打开文件 fstream fs("要打开的文件名",打开 ...
- 学习笔记44—Linux下安装freesurfer
第一步:安装ubuntu (略过) 第二步:下载freesurfer:从freesurfer的官方网站上下载:http://surfer.nmr.mgh.harvard.edu/fswiki/Down ...
- 学习笔记29—Linux基础
一.简单命令: 1.进入文件夹heyi目录:cd ./heyi 2.查看该目录下内容:ls 二.linux压缩和解压缩命令大全 tar命令 解包:tar zxvf FileName.tar 打包:ta ...