/*
字符串长度较小, 可以离线或者直接与处理所有区间的答案
动态加入点的时候, 因为对于其他点的parent构造要么没有影响, 要么就是在两个节点之间塞入一个点, 对于minmax的贡献没有改变
所以只统计这个点的贡献就好了
*/
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cstring>
#include<queue>
#define ll long long
#define M 4040
#define mmp make_pair
using namespace std;
int read()
{
int nm = 0, f = 1;
char c = getchar();
for(; !isdigit(c); c = getchar()) if(c == '-') f = -1;
for(; isdigit(c); c = getchar()) nm = nm * 10 + c - '0';
return nm * f;
} int len[M], fa[M], ch[M][26], lst, cnt;
int ans[2020][2020];
char s[M]; void init()
{
memset(len, 0, sizeof(len));
memset(ch, 0, sizeof(ch));
memset(fa, 0, sizeof(fa));
lst = cnt = 1;
} void insert(int c)
{
int p = ++cnt, f = lst;
lst = p;
len[p] = len[f] + 1;
while(f && !ch[f][c]) ch[f][c] = p, f = fa[f];
if(!f) fa[p] = 1;
else
{
int q = ch[f][c];
if(len[q] == len[f] + 1) fa[p] = q;
else
{
int nq = ++cnt;
fa[nq] = fa[q];
memcpy(ch[nq], ch[q], sizeof(ch[nq]));
len[nq] = len[f] + 1;
fa[p] = fa[q] = nq;
while(f && ch[f][c] == q) ch[f][c] = nq, f = fa[f];
}
}
}
int main()
{
int t = read();
while(t--)
{
//Init();
scanf("%s", s + 1);
int n = strlen(s + 1);
for(int i = 1; i <= n; i++)
{
init();
for(int j = i; j <= n; j++) insert(s[j] - 'a'), ans[i][j] = ans[i][j - 1] + len[lst] - len[fa[lst]];
}
int q = read();
while(q--)
{
int l = read(), r = read();
cout << ans[l][r] << "\n";
}
}
return 0;
}

Hdu 4622 Reincarnation(后缀自动机)的更多相关文章

  1. HDU 4622 Reincarnation 后缀自动机 // BKDRHash(最优hash)

    Reincarnation Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Others) P ...

  2. HDU 4622 Reincarnation 后缀自动机

    模板来源:http://blog.csdn.net/zkfzkfzkfzkfzkfzkfzk/article/details/9669747 解法参考:http://blog.csdn.net/dyx ...

  3. Reincarnation HDU - 4622 (后缀自动机)

    Reincarnation \[ Time Limit: 3000 ms\quad Memory Limit: 65536 kB \] 题意 给出一个字符串 \(S\),然后给出 \(m\) 次查询, ...

  4. hdu 4622 Reincarnation(后缀数组)

    hdu 4622 Reincarnation 题意:还是比较容易理解,给出一个字符串,最长2000,q个询问,每次询问[l,r]区间内有多少个不同的字串. (为了与论文解释统一,这里解题思路里sa数组 ...

  5. HDU 4622 Reincarnation Hash解法详解

    今天想学字符串hash是怎么弄的.就看到了这题模板题 http://acm.hdu.edu.cn/showproblem.php?pid=4622 刚开始当然不懂啦,然后就上网搜解法.很多都是什么后缀 ...

  6. HDU 4622 Reincarnation(后缀自动机)

    [题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=4622 [题目大意] 给出一个长度不超过2000的字符串,有不超过10000个询问,问[L,R]子串 ...

  7. HDU 4622 Reincarnation (查询一段字符串的不同子串个数,后缀自动机)

    Reincarnation Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Others)To ...

  8. hdu 4622 Reincarnation SAM模板题

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4622 题意:给定一个长度不超过2000的字符串,之后有Q次区间查询(Q <= 10000),问区 ...

  9. HDU 6583 Typewriter(后缀自动机)

    Typewrite \[ Time Limit: 1500 ms\quad Memory Limit: 262144 kB \] 题意 给出一个字符串 \(s\),现在你需要构造出这个字符串,你每次可 ...

随机推荐

  1. 查看hp小型机命令集

    查看HP小型机的信息的命令集(一) 1.机型 #model 9000/800/L2000-44 注意:其中44是指每个cpu有440MHZ. 2.cpu个数 #top CPU LOAD USER NI ...

  2. highcharts 知识点

    去掉版权: credits:{ enabled:true // 默认值,如果想去掉版权信息,设置为false即可 }

  3. gets_s()函数的参数太少,strcpy_s():形参和实参 2 的类型不同,等c函数在Visual Studio上出现的问题, get()函数和scanf()读取字符串的区别,栈的随机性

    首先,这些C函数,在VS上要加_s后缀的原因是,这些函数存在字符串越界等问题,可以参考这篇文章,https://blog.csdn.net/silleyj/article/details/854540 ...

  4. streaming简介

    mapreduce和hdfs采用java实现,默认提供java编程接口 streaming框架允许任何程序语言实现的程序在hadoop mapreduce中使用 streaming方便已有的程序向ha ...

  5. C# 构造方法...

    Class1.cs using System; using System.Collections.Generic; using System.Linq; using System.Text; usin ...

  6. tornado请求头/状态码/接口 笔记

    set_header()/set_default_headers() set_header():设置请求头数据 set_default_headers():设置默认请求头数据 import torna ...

  7. shell脚本报错:-bash: xxx: /bin/sh^M: bad interpreter: No such file or directory --引用自http://blog.csdn.net/xiaaiwu/article/details/49126777

    windows下编辑然后上传到linux系统里执行的..sh文件的格式为dos格式.而linux只能执行格式为unix格式的脚本. 我们可以通过vi编辑器来查看文件的format格式.步骤如下: 1. ...

  8. 线程event事件函数实现红绿灯

    #!/usr/bin/env python # -*- coding: utf-8 -*- # author aliex-hrg import threading,time event = threa ...

  9. matlab与示波器连接及电脑连接

    参考:http://blog.sina.com.cn/s/blog_4eff3a0e0100zb8h.html 最近进行了示波器的数据采集,MSO2014,openChoice软件+Tekvisa驱动 ...

  10. msp430及stm32中基本的C编程知识

    为什么我使用P1OUT ^= 0x01;和P1OUT = 0x01 ^是异或计算符号 所以 每次运算都是反转的.而不不加这个运算符就是一直保持1的状态. p1out|=bit6的意思p1out的值如果 ...