Now you have a string consists of uppercase letters, two integers AA and BB. We call a substring wonderful substring when the times it appears in that string is between AA and BB (A \le times \le BA≤times≤B). Can you calculate the number of wonderful substrings in that string?

Input

Input has multiple test cases.

For each line, there is a string SS, two integers AA and BB.

\sum length(S) \le 2 \times 10^6∑length(S)≤2×106,

1 \le A \le B \le length(S)1≤A≤B≤length(S)

Output

For each test case, print the number of the wonderful substrings in a line.

样例输入复制

AAA 2 3
ABAB 2 2

样例输出复制

2
3

题目来源

ACM-ICPC 2018 焦作赛区网络预赛

题解:SAM模板题

参考代码:

 1 //H  求子串出现次数在k1=<num<=k2;
 2 #include <bits/stdc++.h>
 3 using namespace std;
 4 const int MAXN = 4e5+10;
 5 char ss[200005];
 6 const int LetterSize = 26;
 7
 8 int tot, last,ch[MAXN][LetterSize],fa[MAXN],len[MAXN];
 9 int sum[MAXN],tp[MAXN],cnt[MAXN];
10
11 void init()
12 {
13     last = tot = 1;
14     len[1] = 0;
15     memset(ch,0,sizeof ch);
16     memset(fa,0,sizeof fa);
17     memset(cnt,0,sizeof cnt);
18 }
19
20 void add( int x)
21 {
22     int p = last, np = last = ++tot;
23     len[np] = len[p] + 1, cnt[last] = 1;
24     while( p && !ch[p][x]) ch[p][x] = np, p = fa[p];
25     if(p == 0) fa[np] = 1;
26     else
27     {
28         int q = ch[p][x];
29         if( len[q] == len[p] + 1)
30             fa[np] = q;
31         else
32         {
33             int nq = ++tot;
34             memcpy( ch[nq], ch[q], sizeof ch[q]);
35             len[nq] = len[p] + 1, fa[nq] = fa[q], fa[q] = fa[np] = nq;
36             while( p && ch[p][x] == q)  ch[p][x] = nq, p = fa[p];
37         }
38     }
39 }
40
41 void toposort()
42 {
43     for(int i = 1; i <= len[last]; i++)   sum[i] = 0;
44     for(int i = 1; i <= tot; i++)   sum[len[i]]++;
45     for(int i = 1; i <= len[last]; i++)   sum[i] += sum[i-1];
46     for(int i = 1; i <= tot; i++)   tp[sum[len[i]]--] = i;
47 }
48
49
50 int main()
51 {
52
53     int k1,k2;
54     while(scanf("%s",ss)!=EOF)
55     {
56         init();
57         scanf("%d%d",&k1,&k2);
58         long long ans=0;
59         for(int i=0,len=strlen(ss);i<len;i++) add(ss[i]-'A');
60         toposort();
61         for(int i=tot;i;i--)
62         {
63             int p=tp[i],fp=fa[p];
64             cnt[fp]+=cnt[p];
65             if(cnt[p]>=k1 && cnt[p]<=k2) ans+=len[p]-len[fp];
66         }
67         printf("%lld\n",ans);
68     }
69
70     return 0;
71 }

View Code

  

转载于:https://www.cnblogs.com/songorz/p/9651909.html

ACM-ICPC 2018 焦作赛区网络预赛 H题 String and Times(SAM)相关推荐

  1. ICPC 2018 焦作赛区网络预赛G Give Candies 组合数学隔板法+欧拉降幂

    G Give Candies 计蒜客 G Give Candies 题意 n n n个糖果, n n n个人从 1 1 1~ n n n编号,每次给一个人发糖可以发任意数量但不能小于 1 1 1,直到 ...

  2. ACM-ICPC 2018 焦作赛区网络预赛(A B E F G H I K L)

    ACM-ICPC 2018 焦作赛区网络预赛(A B E F G H I K L) 发了博客一万年之后才发现H1写错了(tao A. Magic Mirror 题目链接 题面: Jessie has ...

  3. L. Poor God Water(ACM-ICPC 2018 焦作赛区网络预赛,ac自动机+矩阵快速幂 或 BM线性递推)

    描述 God Water likes to eat meat, fish and chocolate very much, but unfortunately, the doctor tells hi ...

  4. ACM-ICPC 2018 焦作赛区网络预赛 A. Magic Mirror (水)| B . Mathematical Curse(dp)

    A 题目: Jessie has a magic mirror. Every morning she will ask the mirror: 'Mirror mirror tell me, who ...

  5. ACM-ICPC 2018 焦作赛区网络预赛 J(二分+JAVA高精)

    传送门 题面: 65536K Jessie and Justin want to participate in e-sports. E-sports contain many games, but t ...

  6. ACM-ICPC 2018 焦作赛区网络预赛

    Give Candies 题意:有n颗糖,有n个人,按顺序出列,每次随机给那个人一些糖(至少一颗),分完为止,求有多少方案 思路:规律是2^(n−1) 根据费马小定理  a^(p−1)=1(mod p ...

  7. ACM-ICPC 2018 焦作赛区网络预赛 L Poor God Water(BM算法)

    题目链接:https://nanti.jisuanke.com/t/31721 题目大意:三种食物,n小时,连续三小时不能吃一样的东西,中间吃巧克力时连续三个小时吃的东西不能完全不同,如果中间吃鱼或者 ...

  8. ACM-ICPC 2018 焦作赛区网络预赛 L. Poor God Water

    #题解 大佬的递推式子..本弱鸡具体怎么得到的也不是很清楚 f(1)=3,f(2)=9,f(3)=20,f(4)=46,f(5)=106 f(n)=2f(n-1)-f(n-2)+3f(n-3)+2*f ...

  9. ACM-ICPC 2018 焦作赛区网络预赛A. Magic Mirror(签到题)

    Jessie has a magic mirror. Every morning she will ask the mirror: 'Mirror mirror tell me, who is the ...

最新文章

  1. Spring Cloud Alibaba---服务注册、发现、管理中心Nacos
  2. oracle中or的替函数,Oracle常用内置Or自定义函数-SQL宝典
  3. Ubuntu 12.04下PostgreSQL-9.1安装与配置详解(在线安装)
  4. java后台访问接口
  5. 第一章:递推与递归 【完结】
  6. 《剑指offer》-- 和为S的连续整数序列、和为S的两个数字、左旋转字符串、翻转单词顺序列
  7. Java刷漆问题代码_Java实现蓝桥杯历届试题格子刷油漆
  8. c#子线程和主线程创建窗体时顶层显示的区别
  9. 2019年第十届蓝桥杯 C / C ++省赛 B 组真题题解
  10. springboot用户管理系统_Springboot优秀开源项目
  11. “两小学生研究喝茶抗癌获奖”,官方回应:经老师培训独立完成
  12. Java 蓝桥杯 字母图形
  13. windows server2008 r2 下启用 sqlserver 2008的远程连接
  14. Element-UI 要怎么学?官方文档!
  15. java 中的 ThreadLocal
  16. 剑指offer例题分享--6
  17. IPTV在线服务器地址,德芯IPTV网关服务器,德芯直播点播服务器
  18. python回归分析波士顿房价_python 线性回归(Linear Regression)预测波士顿房价
  19. 基于MATLAB的求解线性方程组(附完整代码和例题)
  20. 【概率论】- (2)假设检验

热门文章

  1. 【RK3399Pro学习笔记】八、ROS话题消息的定义与使用
  2. Exynos4412裸机开发 —— UART
  3. lxml学习【未完成】
  4. VS.NET版本与VC版本对应关系
  5. makefile中的patsubst, wildcard, notdir
  6. 通过进程ID获取基地址
  7. python实现手机号归属地相关信息查询
  8. epoll为什么比select和poll效率更高
  9. nuc972的ramfs的配置yaffs2,ubi文件系统
  10. [react] react中的setState缺点是什么呢?