Language: C++

#include <iostream>
#include <vector>
#include <algorithm>
#include <climits>

#pragma once
#include <vector>
#include <iostream>

namespace Jin {

	template<class T, class Func>
	class Segment_Tree {

	private:
		std::vector<T> data;
		size_t height;//セグメント木の階層の数
		Func func;
		T invalid;//無効な値(要素数を2のべき乗に合わせるため)

		//[l,r)は半開区間.kは木における添え字.leftとrightはノードが担当する区間
		T get(size_t l, size_r, size_t k, size_t left, size_t right)const {
			if (right <= l || r <= left)return invalid;//そのノードの区間が全くクエリの範囲と被ってない場合は無効の値を返す。
			if (l <= left && right <= r)return data[k];//もし、ノードの区間がクエリの範囲に収まっていたら、そのノードを返す。
			T a = get(l, r, k * 2 + 1, left, (left + right) / 2);
			T b = get(l, r, k * 2 + 2, (left + right) / 2, right);
			return func(a, b);
		}

	public:
		Segment_Tree(Itr first, Itr last, Func func, T invalid) {
			size_t dif = std::distance(first, last);
			bottom_size = 1;
			while (bottom_size < dif) {
				bottom_size <<= 1;
				height++;
			}
			data.resize(2 * bottom_size - 1, invalid);
			for (size_t i = 0; i < 2 * bottom_size - 1; i++) {

			}
		}

		void update(size_t i, int value) {
			i += bottom_size - 1;
			data[i] = value;
			while (i > 0) {
				i = (i - 1) / 2;
				data[i] = func(data[i * 2 + 1], data[i * 2 + 2]);
			}
		}

		T get(size_t l, size_t r)const {
			return get(l, r, 0, 0, bottom_size);
		}

		void show()const {
			for (size_t i = 0; i < 2 * bottom_size - 1; ++i) {
				std::cout << data[i] << ",";
				if (!((i + 2) & (i + 1)))std::cout << '\n';
			}
		}

	};

	template<class T, class Itr, class Func>
	auto make_segment_tree(Itr first, Itr last, Func func, T init) {
		return Segment_Tree<T, Func>(first, last, func, init);
	}

}

using namespace std;
using ll = long long;

int main() {

	cin.tie(nullptr); ios::sync_with_stdio(false);

	int N, Q; cin >> N >> Q;
	string S; cin >> S;
	vector<int> AC(N, 0); for (int i = 1; i < N; i++) {
		if (S[i - 1] == 'A' && S[i] == 'C')AC[i] = 1;
	}

	auto seg = Jin::make_segment_tree(AC.begin(), AC.end(), [](int a, int b) {return a + b; }, 0);

	for (size_t i = 0; i < Q; i++)
	{
		int l, r; cin >> l >> r;
		
		cout << seg.get(l, r);
	}

	return 0;

}

Compiler output:
a.cc:6:9: warning: #pragma once in main file
    6 | #pragma once
      |         ^~~~
a.cc:22:33: error: 'size_r' has not been declared
   22 |                 T get(size_t l, size_r, size_t k, size_t left, size_t right)const {
      |                                 ^~~~~~
a.cc:31:33: error: expected ')' before 'first'
   31 |                 Segment_Tree(Itr first, Itr last, Func func, T invalid) {
      |                             ~   ^~~~~~
      |                                 )
a.cc: In member function 'T Jin::Segment_Tree<T, Func>::get(size_t, int, size_t, size_t, size_t) const':
a.cc:23:43: error: 'r' was not declared in this scope
   23 |                         if (right <= l || r <= left)return invalid;//そのノードの区間が全くクエリの範囲と被ってない場合は無効の値を返す。
      |                                           ^
a.cc:24:51: error: 'r' was not declared in this scope
   24 |                         if (l <= left && right <= r)return data[k];//もし、ノードの区間がクエリの範囲に収まっていたら、そのノードを返す。
      |                                                   ^
a.cc:25:38: error: 'r' was not declared in this scope
   25 |                         T a = get(l, r, k * 2 + 1, left, (left + right) / 2);
      |                                      ^
a.cc: In member function 'void Jin::Segment_Tree<T, Func>::update(size_t, int)':
a.cc:45:30: error: 'bottom_size' was not declared in this scope
   45 |                         i += bottom_size - 1;
      |                              ^~~~~~~~~~~
a.cc: In member function 'T Jin::Segment_Tree<T, Func>::get(size_t, size_t) const':
a.cc:54:48: error: 'bottom_size' was not declared in this scope
   54 |                         return get(l, r, 0, 0, bottom_size);
      |                                                ^~~~~~~~~~~
a.cc: In member function 'void Jin::Segment_Tree<T, Func>::show() const':
a.cc:58:52: error: 'bottom_size' was not declared in this scope
   58 |                         for (size_t i = 0; i < 2 * bottom_size - 1; ++i) {
      |                                                    ^~~~~~~~~~~
a.cc: In instantiation of 'auto Jin::make_segment_tree(Itr, Itr, Func, T) [with T = int; Itr = __gnu_cxx::__normal_iterator<int*, std::vector<int> >; Func = main()::<lambda(int, int)>]':
a.cc:86:35:   required from here
   86 |         auto seg = Jin::make_segment_tree(AC.begin(), AC.end(), [](int a, int b) {return a + b; }, 0);
      |                    ~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:68:24: error: no matching function for call to 'Jin::Segment_Tree<int, main()::<lambda(int, int)> >::Segment_Tree(__gnu_cxx::__normal_iterator<int*, std::vector<int> >&, __gnu_cxx::__normal_iterator<int*, std::vector<int> >&, main()::<lambda(int, int)>&, int&)'
   68 |                 return Segment_Tree<T, Func>(first, last, func, init);
      |                        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:13:15: note: candidate: 'Jin::Segment_Tree<int, main()::<lambda(int, int)> >::Segment_Tree(const Jin::Segment_Tree<int, main()::<lambda(int, int)> >&)'
   13 |         class Segment_Tree {
      |               ^~~~~~~~~~~~
a.cc:13:15: note:   candidate expects 1 argument, 4 provided
a.cc:13:15: note: candidate: 'Jin::Segment_Tree<int, main()::<lambda(int, int)> >::Segment_Tree(Jin::Segment_Tree<int, main()::<lambda(int, int)> >&&)'
a.cc:13:15: note:   candidate expects 1 argument, 4 provided