题意:给你多个数字串,求本质不同的子串和(去掉前导零)

题解:建广义sam,刚开始一直想的是用l来计算,发现前导零对l的影响根本消不掉,所以不会做= =,原来应该是直接用一个新的数组表示到当前有多少个子串就好了

  1. //#pragma GCC optimize(2)
  2. //#pragma GCC optimize(3)
  3. //#pragma GCC optimize(4)
  4. //#pragma GCC optimize("unroll-loops")
  5. //#pragma comment(linker, "/stack:200000000")
  6. //#pragma GCC optimize("Ofast,no-stack-protector")
  7. //#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
  8. #include<bits/stdc++.h>
  9. #define fi first
  10. #define se second
  11. #define db double
  12. #define mp make_pair
  13. #define pb push_back
  14. #define pi acos(-1.0)
  15. #define ll long long
  16. #define vi vector<int>
  17. #define mod 2012
  18. #define ld long double
  19. #define C 0.5772156649
  20. #define ls l,m,rt<<1
  21. #define rs m+1,r,rt<<1|1
  22. #define pll pair<ll,ll>
  23. #define pil pair<int,ll>
  24. #define pli pair<ll,int>
  25. #define pii pair<int,int>
  26. //#define cd complex<double>
  27. #define ull unsigned long long
  28. #define base 1000000000000000000
  29. #define Max(a,b) ((a)>(b)?(a):(b))
  30. #define Min(a,b) ((a)<(b)?(a):(b))
  31. #define fin freopen("a.txt","r",stdin)
  32. #define fout freopen("c.txt","w",stdout)
  33. #define fio ios::sync_with_stdio(false);cin.tie(0)
  34. template<typename T>
  35. inline T const& MAX(T const &a,T const &b){return a>b?a:b;}
  36. template<typename T>
  37. inline T const& MIN(T const &a,T const &b){return a<b?a:b;}
  38. inline void add(ll &a,ll b){a+=b;if(a>=mod)a-=mod;}
  39. inline void sub(ll &a,ll b){a-=b;if(a<0)a+=mod;}
  40. inline ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
  41. 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;}
  42. 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;}
  43. using namespace std;
  44. const double eps=1e-8;
  45. const ll INF=0x3f3f3f3f3f3f3f3f;
  46. const int N=100000+10,maxn=100000+10,inf=0x3f3f3f3f;
  47. char s[N];
  48. struct SAM{
  49. int last,cnt;
  50. int ch[N<<1][10],fa[N<<1],l[N<<1],c[N<<1];
  51. int a[N<<1],num[N<<1],sum[N<<1];
  52. void init()
  53. {
  54. cnt=1;
  55. }
  56. void ins(int x)
  57. {
  58. if(ch[last][x])
  59. {
  60. int p=last,q=ch[last][x];
  61. if(l[q]==l[p]+1)last=q;
  62. else
  63. {
  64. int nq=++cnt;l[nq]=l[p]+1;
  65. memcpy(ch[nq],ch[q],sizeof ch[q]);
  66. fa[nq]=fa[q];fa[q]=last=nq;
  67. for(;ch[p][x]==q;p=fa[p])ch[p][x]=nq;
  68. }
  69. return ;
  70. }
  71. int p=last,np=++cnt;last=np;l[np]=l[p]+1;
  72. for(;p&&!ch[p][x];p=fa[p])ch[p][x]=np;
  73. if(!p)fa[np]=1;
  74. else
  75. {
  76. int q=ch[p][x];
  77. if(l[q]==l[p]+1)fa[np]=q;
  78. else
  79. {
  80. int nq=++cnt;l[nq]=l[p]+1;
  81. memcpy(ch[nq],ch[q],sizeof ch[q]);
  82. fa[nq]=fa[q];fa[q]=fa[np]=nq;
  83. for(;ch[p][x]==q;p=fa[p])ch[p][x]=nq;
  84. }
  85. }
  86. }
  87. void topo()
  88. {
  89. for(int i=1;i<=cnt;i++)c[l[i]]++;
  90. for(int i=1;i<=cnt;i++)c[i]+=c[i-1];
  91. for(int i=1;i<=cnt;i++)a[c[l[i]]--]=i;
  92. }
  93. void build()
  94. {
  95. last=1;
  96. int len=strlen(s+1);
  97. for(int i=1;i<=len;i++)ins(s[i]-'0');
  98. }
  99. void cal()
  100. {
  101. topo();
  102. num[1]=1;
  103. for(int i=1;i<=cnt;i++)
  104. {
  105. int p=a[i];
  106. for(int j=0;j<10;j++)
  107. if(ch[p][j])
  108. {
  109. if(i==1&&j==0)continue;
  110. num[ch[p][j]]+=num[p];
  111. sum[ch[p][j]]=(sum[ch[p][j]]+(sum[p]*10+num[p]*j)%mod)%mod;
  112. }
  113. }
  114. int ans=0;
  115. for(int i=1;i<=cnt;i++)
  116. ans=(ans+sum[i])%mod;
  117. printf("%d\n",ans);
  118. for(int i=0;i<=cnt;i++)
  119. {
  120. for(int j=0;j<10;j++)ch[i][j]=0;
  121. sum[i]=fa[i]=num[i]=a[i]=c[i]=l[i]=0;
  122. }
  123. }
  124. }sam;
  125. int main()
  126. {
  127. // fin;
  128. int n;
  129. while(~scanf("%d",&n))
  130. {
  131. sam.init();
  132. for(int i=0;i<n;i++)
  133. {
  134. scanf("%s",s+1);
  135. sam.build();
  136. }
  137. sam.cal();
  138. }
  139. return 0;
  140. }
  141. /********************
  142. 3
  143. 12
  144. 012
  145. 0012
  146. ********************/

HDU - 4436sam裸题的更多相关文章

  1. hdu 1711kmp裸题

    #include<stdio.h> #define N 1000050 int text[N],t[N],next[N],n,m; void getnext() { int j=0,k=- ...

  2. HDU 1102 最小生成树裸题,kruskal,prim

    1.HDU  1102  Constructing Roads    最小生成树 2.总结: 题意:修路,裸题 (1)kruskal //kruskal #include<iostream> ...

  3. HDU 1248 寒冰王座(完全背包裸题)

    寒冰王座 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submi ...

  4. HDU 2602 Bone Collector(01背包裸题)

    Bone Collector Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) T ...

  5. HDU 1711 Number Sequence(KMP裸题,板子题,有坑点)

    Number Sequence Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  6. hdu Flow Problem (最大流 裸题)

    最大流裸题,贴下模版 view code#include <iostream> #include <cstdio> #include <cstring> #incl ...

  7. hdu_3966_Aragorn's Story(树链剖分裸题)

    题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=3966 题意:给你一棵树,然后给定点之间的路径权值修改,最后单点查询 题解:树链剖分裸题,这里我用树状数 ...

  8. hdu-2602&&POJ-3624---01背包裸题

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=2602 https://vjudge.net/problem/POJ-3624 都是01背包的裸题 这 ...

  9. 13-Oulipo(kmp裸题)

    http://acm.hdu.edu.cn/showproblem.php?pid=1686 Oulipo Time Limit: 3000/1000 MS (Java/Others)    Memo ...

随机推荐

  1. JavaI/O(输入/输出)

    File类 通过File类可以在程序中操作文件和目录,File能新建.删除.重命名文件和目录,但是不能访问文件内容本身. 理解I/O流 流(stream)是从起源(source)到接收(sink)的有 ...

  2. (转) RNN models for image generation

    RNN models for image generation MARCH 3, 2017   Today we’re looking at the remaining papers from the ...

  3. 浅谈 Make 命令

    代码变成可执行文件,叫做编译(compile):先编译这个,还是先编译那个(即编译的安排),叫做构建(build). Make是最常用的构建工具,诞生于1977年,主要用于C语言的项目.但是实际上 , ...

  4. Eclipse卸载插件SpringSoource-tool-suite

    Eclipse卸载插件SpringSoource-tool-suite **系统环境:**Mac OS X 引子: 一直在纠结的一个问题,就是Eclipse开发java 项目在配置了InternalR ...

  5. 程序设计第二次作业<2>

    我所找到的C++相关课程列表: (2016/1/27)(部分) 1. 慕课网 http://www.imooc.com/learn/342 <c++远征之起航篇> 授课人:james_yu ...

  6. 5、web站点架构模式简介及Nginx

    LB Cluster: 提升系统容量的方式: scale up:向上扩展 scale out:向外扩展 LVS工作在内核中,本身的数量不受套接字数量限制,利用LVS做调度器,优化得当的话,并发数量可以 ...

  7. FI 业务

    f-02 post f-03 clear[account]-> f-04 post with clear fb70/f-22 f-32 clear[account]->f-28 post ...

  8. [原][osgEarth]在osgearth中添加相机路径动画

    在osg中添加相机动画路径请参考:http://www.cnblogs.com/lyggqm/p/8075277.html 这里的代码是在osgearth中添加相机动画路径漫游器: #include ...

  9. 要使用myConfig.properties配置文件作为实体类的映射文件的话,格式要用=,最关键的要和实例类中通过反射获取值的KEY要一样,不样会反射取不到值

    ABC=https://fsdfsdf.iy.comABCId=L2345345ZhP345ABCKey=sfdf4234f234dhE6Ut0aABCName=Gassd010 上面是myConfi ...

  10. 解决在Vue项目中时常因为代码缩进导致页面报错的问题

    前言 如果我们初次使用vue-cli来构建单页SPA应用,在撸代码的过程中有可能会遇到这种因为代码缩进导致 页面报错的问题,导致我们烦不胜烦.接下来我们就来看一看如何解决这个小问题... erro原因 ...