Language: C++

#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

typedef long long LL;

const int maxn = 1e6 + 10;
const int M = 26;

char s[maxn];
int next[maxn];

struct Node
{
	LL cnt[M];
	Node() { memset(cnt, 0, sizeof cnt); }
	void operator += (const Node &a)
	{
		for (int i = 0; i < M; ++ i)
			cnt[i] += a.cnt[i];
	}
	Node operator + (const Node &a) const
	{
		Node res;
		for (int i = 0; i < M; ++ i)
			res.cnt[i] = cnt[i] + a.cnt[i];
		return res;
	}
	Node operator - (const Node &a) const
	{
		Node res;
		for (int i = 0; i < M; ++ i)
			res.cnt[i] = cnt[i] - a.cnt[i];
		return res;
	}
	void Putout()
	{
		for (int i = 0; i < M - 1; ++ i) printf("%lld ", cnt[i]);
		printf("%lld\n", cnt[M - 1]);
	}
} sum[maxn];

Node Calc(int len, LL n)
{
	LL x = len, y = len + (len - next[len]);
	if (n <= x) return sum[n];
	if (n <= y) return sum[len] + sum[n - len];
	Node a = sum[len], b = sum[len] + sum[len - next[len]];
	while (n >= x + y)
	{
		b += a;
		a = b - a;
		y += x;
		x = y - x;
	}
	return b + Calc(len, n - y);
}

int main()
{
	scanf("%s", s + 1);
	int n = strlen(s + 1) / 2;
	next[1] = 0;
	sum[1].cnt[s[1] - 'a'] = 1;
	for (int i = 2; i <= n; ++ i)
	{
		int j = next[i - 1];
		while (j && s[j + 1] != s[i]) j = next[j];
		next[i] = j + (s[j + 1] == s[i]);
		sum[i].cnt[s[i] - 'a'] = 1;
		sum[i] += sum[i - 1];
	}
	LL l, r;
	scanf("%lld%lld", &l, &r);
	Node res = Calc(n, r) - Calc(n, l - 1);
	res.Putout();
	return 0;
}


Compiler output:
a.cc: In function 'Node Calc(int, LL)':
a.cc:47:38: error: reference to 'next' is ambiguous
   47 |         LL x = len, y = len + (len - next[len]);
      |                                      ^~~~
In file included from /usr/include/c++/14/bits/stl_algobase.h:66,
                 from /usr/include/c++/14/algorithm:60,
                 from a.cc:3:
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:232:5: note: candidates are: 'template<class _InputIterator> constexpr _InputIterator std::next(_InputIterator, typename iterator_traits<_Iter>::difference_type)'
  232 |     next(_InputIterator __x, typename
      |     ^~~~
a.cc:13:5: note:                 'int next [1000010]'
   13 | int next[maxn];
      |     ^~~~
a.cc:50:53: error: reference to 'next' is ambiguous
   50 |         Node a = sum[len], b = sum[len] + sum[len - next[len]];
      |                                                     ^~~~
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:232:5: note: candidates are: 'template<class _InputIterator> constexpr _InputIterator std::next(_InputIterator, typename iterator_traits<_Iter>::difference_type)'
  232 |     next(_InputIterator __x, typename
      |     ^~~~
a.cc:13:5: note:                 'int next [1000010]'
   13 | int next[maxn];
      |     ^~~~
a.cc: In function 'int main()':
a.cc:65:9: error: reference to 'next' is ambiguous
   65 |         next[1] = 0;
      |         ^~~~
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:232:5: note: candidates are: 'template<class _InputIterator> constexpr _InputIterator std::next(_InputIterator, typename iterator_traits<_Iter>::difference_type)'
  232 |     next(_InputIterator __x, typename
      |     ^~~~
a.cc:13:5: note:                 'int next [1000010]'
   13 | int next[maxn];
      |     ^~~~
a.cc:69:25: error: reference to 'next' is ambiguous
   69 |                 int j = next[i - 1];
      |                         ^~~~
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:232:5: note: candidates are: 'template<class _InputIterator> constexpr _InputIterator std::next(_InputIterator, typename iterator_traits<_Iter>::difference_type)'
  232 |     next(_InputIterator __x, typename
      |     ^~~~
a.cc:13:5: note:                 'int next [1000010]'
   13 | int next[maxn];
      |     ^~~~
a.cc:70:51: error: reference to 'next' is ambiguous
   70 |                 while (j && s[j + 1] != s[i]) j = next[j];
      |                                                   ^~~~
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:232:5: note: candidates are: 'template<class _InputIterator> constexpr _InputIterator std::next(_InputIterator, typename iterator_traits<_Iter>::difference_type)'
  232 |     next(_InputIterator __x, typename
      |     ^~~~
a.cc:13:5: note:                 'int next [1000010]'
   13 | int next[maxn];
      |     ^~~~
a.cc:71:17: error: reference to 'next' is ambiguous
   71 |                 next[i] = j + (s[j + 1] == s[i]);
      |                 ^~~~
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:232:5: note: candidates are: 'template<class _InputIterator> constexpr _InputIterator std::next(_InputIterator, typename iterator_traits<_Iter>::difference_type)'
  232 |     next(_InputIterator __x, typename
      |     ^~~~
a.cc:13:5: note:                 'int next [1000010]'
   13 | int next[maxn];
      |     ^~~~