Language: C++

#include <cstdio>
#include <cstring>
#include <algorithm>
#define N 200006
using namespace std;
char s[N];long long f[106],g[106][26],a[26],l,r,x;
int n,p,t,v[26],height[N],sa[N],rank[N],tsa[N],cntA[N],cntB[N],A[N],B[N];
inline int read()
{
	int x=0,c=getchar(),f=1;while(c<'0'||c>'9')f=(c=='-'?-f:f),c=getchar();
	while(c>='0'&&c<='9')x=(x<<1)+(x<<3)+c-48,c=getchar();return f>0?x:-x;
}
void print(long long x)
{
	if(x>9)print(x/10);putchar(x%10+48);
}
void SA()
{
	for(int i=1;i<=n;i++)cntA[(int)s[i]]++;
	for(int i=1;i<N;i++)cntA[i]+=cntA[i-1];
	for(int i=n;i;i--)sa[cntA[(int)s[i]]--]=i;
	rank[sa[1]]=1;
	for(int i=2;i<=n;i++){
		rank[sa[i]]=rank[sa[i-1]];
		if(s[sa[i]]!=s[sa[i-1]])rank[sa[i]]++;
	}
	for(int l=1;rank[sa[n]]!=n;l<<=1){
		for(int i=0;i<N;i++)cntA[i]=cntB[i]=0;
		for(int i=1;i<=n;i++){
			cntA[A[i]=rank[i]]++;
			cntB[B[i]=(i+l<=n?rank[i+l]:0)]++;
		}
		for(int i=1;i<N;i++)cntA[i]+=cntA[i-1],cntB[i]+=cntB[i-1];
		for(int i=n;i;i--)tsa[cntB[B[i]]--]=i;
		for(int i=n;i;i--)sa[cntA[A[tsa[i]]]--]=tsa[i];
		rank[sa[1]]=1;
		for(int i=2;i<=n;i++){
			rank[sa[i]]=rank[sa[i-1]];
			if(A[sa[i]]!=A[sa[i-1]]||B[sa[i]]!=B[sa[i-1]])rank[sa[i]]++;
		}
	}
	int tot=0;
	for(int i=1;i<=n;i++){
		if(tot)tot--;
		while(s[i+tot]==s[sa[rank[i]-1]+tot])tot++;
		height[rank[i]]=tot;
	}
	p=n;int mi=N;
	for(int i=rank[1];i>=2;i--){
		mi=min(mi,height[i]);
		if(mi==n-sa[i-1]+1)p=min(p,sa[i-1]-1);
	}mi=N;
	for(int i=rank[1]+1;i<=n;i++){
		mi=min(mi,height[i]);
		if(mi==n-sa[i]+1)p=min(p,sa[i]-1);
	}
}
void wk(int w,int F)
{
	if(x==0)return;
	if(f[w]>x)
		if(w>2){wk(w-1,F);if(x)wk(w-2,F);}
		else{for(int i=1;i<=x;i++)a[s[i]-97]+=F;x=0;}
	else{for(int i=0;i<26;i++)a[i]+=F*g[w][i];x-=f[w];}
}
int main()
{
	scanf("%s",s+1);
	n=strlen(s+1)/2;scanf("%lld%lld",&l,&r);SA();
	for(int i=1;i<=p;i++)v[s[i]-97]++;
	if(n%p==0){
		if(r<=n)for(int i=l;i<=r;i++)a[s[i]-97]++;
		else{
			if(l<=n)for(int i=l;i<=n;i++)a[s[i]-97]++;
			else for(int i=(l-n)%p;i<=p;i++)a[s[i]-97]++;
			r-=n;for(int i=1;i<=r%p;i++)a[s[i]-97]++;
			for(int i=0;i<26;i++)a[i]+=1LL*v[i]*(r/p-(l<=n?0:(l-n-1)/p+1));
		}
	}else{
		f[1]=n;f[2]=n+p;
		for(int i=1;i<=n;i++)g[1][s[i]-97]=++g[2][s[i]-97];
		for(int i=0;i<26;i++)g[2][i]+=v[i];
		for(t=3;f[t-1]<r;t++){
			f[t]=f[t-1]+f[t-2];
			for(int i=0;i<26;i++)g[t][i]+=g[t-1][i]+g[t-2][i];
		}t--;
		x=r;wk(t,1);if(l>1)x=l-1,wk(t,-1);
	}
	for(int i=0;i<25;i++)printf("%lld ",a[i]);printf("%lld\n",a[25]);
}

Compiler output:
a.cc: In function 'void SA()':
a.cc:22:9: error: reference to 'rank' is ambiguous
   22 |         rank[sa[1]]=1;
      |         ^~~~
In file included from /usr/include/c++/14/bits/stl_pair.h:60,
                 from /usr/include/c++/14/bits/stl_algobase.h:64,
                 from /usr/include/c++/14/algorithm:60,
                 from a.cc:3:
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:7:33: note:                 'int rank [200006]'
    7 | int n,p,t,v[26],height[N],sa[N],rank[N],tsa[N],cntA[N],cntB[N],A[N],B[N];
      |                                 ^~~~
a.cc:24:17: error: reference to 'rank' is ambiguous
   24 |                 rank[sa[i]]=rank[sa[i-1]];
      |                 ^~~~
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:7:33: note:                 'int rank [200006]'
    7 | int n,p,t,v[26],height[N],sa[N],rank[N],tsa[N],cntA[N],cntB[N],A[N],B[N];
      |                                 ^~~~
a.cc:24:29: error: reference to 'rank' is ambiguous
   24 |                 rank[sa[i]]=rank[sa[i-1]];
      |                             ^~~~
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:7:33: note:                 'int rank [200006]'
    7 | int n,p,t,v[26],height[N],sa[N],rank[N],tsa[N],cntA[N],cntB[N],A[N],B[N];
      |                                 ^~~~
a.cc:25:41: error: reference to 'rank' is ambiguous
   25 |                 if(s[sa[i]]!=s[sa[i-1]])rank[sa[i]]++;
      |                                         ^~~~
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:7:33: note:                 'int rank [200006]'
    7 | int n,p,t,v[26],height[N],sa[N],rank[N],tsa[N],cntA[N],cntB[N],A[N],B[N];
      |                                 ^~~~
a.cc:27:21: error: reference to 'rank' is ambiguous
   27 |         for(int l=1;rank[sa[n]]!=n;l<<=1){
      |                     ^~~~
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:7:33: note:                 'int rank [200006]'
    7 | int n,p,t,v[26],height[N],sa[N],rank[N],tsa[N],cntA[N],cntB[N],A[N],B[N];
      |                                 ^~~~
a.cc:30:35: error: reference to 'rank' is ambiguous
   30 |                         cntA[A[i]=rank[i]]++;
      |                                   ^~~~
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:7:33: note:                 'int rank [200006]'
    7 | int n,p,t,v[26],height[N],sa[N],rank[N],tsa[N],cntA[N],cntB[N],A[N],B[N];
      |                                 ^~~~
a.cc:31:43: error: reference to 'rank' is ambiguous
   31 |                         cntB[B[i]=(i+l<=n?rank[i+l]:0)]++;
      |                                           ^~~~
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:7:33: note:                 'int rank [200006]'
    7 | int n,p,t,v[26],height[N],sa[N],rank[N],tsa[N],cntA[N],cntB[N],A[N],B[N];
      |                                 ^~~~
a.cc:36:17: error: reference to 'rank' is ambiguous
   36 |                 rank[sa[1]]=1;
      |                 ^~~~
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:7:33: note:                 'int rank [200006]'
    7 | int n,p,t,v[26],height[N],sa[N],rank[N],tsa[N],cntA[N],cntB[N],A[N],B[N];
      |                                 ^~~~
a.cc:38:25: error: reference to 'rank' is ambiguous
   38 |                         rank[sa[i]]=rank[sa[i-1]];
      |                         ^~~~
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:7:33: note:                 'int rank [200006]'
    7 | int n,p,t,v[26],height[N],sa[N],rank[N],tsa[N],cntA[N],cntB[N],A[N],B[N];
      |                                 ^~~~
a.cc:38:37: error: reference to 'rank' is ambiguous
   38 |                         rank[sa[i]]=rank[sa[i-1]];
      |                                     ^~~~
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:7:33: note:                 'int rank [200006]'
    7 | int n,p,t,v[26],height[N],sa[N],rank[N],tsa[N],cntA[N],cntB[N],A[N],B[N];
      |                                 ^~~~
a.cc:39:71: error: reference to 'rank' is ambiguous
   39 |                         if(A[sa[i]]!=A[sa[i-1]]||B[sa[i]]!=B[sa[i-1]])rank[sa[i]]++;
      |                                                                       ^~~~
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:7:33: note:                 'int rank [200006]'
    7 | int n,p,t,v[26],height[N],sa[N],rank[N],tsa[N],cntA[N],cntB[N],A[N],B[N];
      |                                 ^~~~
a.cc:45:38: error: reference to 'rank' is ambiguous
   45 |                 while(s[i+tot]==s[sa[rank[i]-1]+tot])tot++;
      |                                      ^~~~
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:7:33: note:                 'int rank [200006]'
    7 | int n,p,t,v[26],height[N],sa[N],rank[N],tsa[N],cntA[N],cntB[N],A[N],B[N];
      |                                 ^~~~
a.cc:46:24: error: reference to 'rank' is ambiguous
   46 |                 height[rank[i]]=tot;
      |                        ^~~~
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:7:33: note:                 'int rank [200006]'
    7 | int n,p,t,v[26],height[N],sa[N],rank[N],tsa[N],cntA[N],cntB[N],A[N],B[N];
      |                                 ^~~~
a.cc:49:19: error: reference to 'rank' is ambiguous
   49 |         for(int i=rank[1];i>=2;i--){
      |                   ^~~~
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:7:33: note:                 'int rank [200006]'
    7 | int n,p,t,v[26],height[N],sa[N],rank[N],tsa[N],cntA[N],cntB[N],A[N],B[N];
      |                                 ^~~~
a.cc:53:19: error: reference to 'rank' is ambiguous
   53 |         for(int i=rank[1]+1;i<=n;i++){
      |                   ^~~~
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:7:33: note:                 'int rank [200006]'
    7 | int n,p,t,v[26],height[N],sa[N],rank[N],tsa[N],cntA[N],cntB[N],A[N],B[N];
      |                                 ^~~~