题目描述
给你一个字符串s由小写字母组成,有q组询问,每组询问给你两个数,l和r,问在字符串区间l到r的字串中,包含多少回文串。
时空限制
5000ms,256MB
输入格式
第1行,给出s,s的长度小于5000 第2行给出q(1<=q<=10^6) 第2至2+q行 给出每组询问的l和r
输出格式
输出每组询问所问的数量。
样例
样例输入
caaaba
5
1 1
1 4
2 3
4 6
4 5
样例输出
1
7
3
4
2
题解
通常思路不止一种,由于时间给的宽泛,这里给出记忆化搜索的方案。
我们直接搜索每一个状态即可
#include
#include
#define int long long
#define maxn 5005
using namespace std;
inline char get(){
static char buf[30000],*p1=buf,*p2=buf;
return p1==p2 && (p2=(p1=buf)+fread(buf,1,30000,stdin),p1==p2)?EOF:*p1++;
}
inline int read(){
register char c=get();register int f=1,_=0;
while(c>'9' || c<'0')f=(c=='-')?-1:1,c=get();
while(c<='9' && c>='0')_=(_<<3)+(_<<1)+(c^48),c=get();
return _*f;
}
string s;
inline bool is_(int l,int r){
for(;l