Pagini recente » Cod sursa (job #2372593) | Cod sursa (job #1897782) | Cod sursa (job #2007510) | Cod sursa (job #2197219) | Cod sursa (job #3302769)
#include <fstream>
using namespace std;
ifstream cin("pscpld.in");
ofstream cout("pscpld.out");
///#define int long long
struct node{
int st,dr,lung;
int next[26];
int suf; long long cnt;
};
node root1,root2;
node v[1000001];
int cur,poz;
string s;
void insertie(int ind){
int aux=cur,curl;
while(true){
curl=v[aux].lung;
if(ind-curl>=1 && s[ind]==s[ind-curl-1]) break;
aux=v[aux].suf;
}
if(v[aux].next[s[ind]-'a']){
///cout<<"a";
cur=v[aux].next[s[ind]-'a'];
v[cur].cnt++;
return ;
}
poz++;
v[aux].next[s[ind]-'a']=poz;
v[poz].lung=v[aux].lung+2;
v[poz].dr=ind;
v[poz].st=ind-v[poz].lung+1;
v[poz].cnt=1;
aux=v[aux].suf;cur=poz;
if(v[cur].lung==1){
v[cur].suf=2;
return;
}
while(true){
curl=v[aux].lung;
if(ind-curl>=1 && s[ind]==s[ind-curl-1]) break;
aux=v[aux].suf;
}
v[cur].suf=v[aux].next[s[ind]-'a'];
}
signed main()
{
int i;
long long rasp=0;
root1.lung=-1;root2.lung=0;
root1.suf=root2.suf=1;
v[1]=root1;v[2]=root2;
poz=2;cur=1;
cin>>s;
for(i=0;i<s.size();i++){
insertie(i);
}
for(i=poz;i>=3;i--) {
v[v[i].suf].cnt+=v[i].cnt;
}
for(i=3;i<=poz;i++){
rasp+=v[i].cnt;///cout<<v[i].cnt<<" ";
}
cout<<rasp;
return 0;
}