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_t 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:
		template<class Itr>
		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: In constructor 'Jin::Segment_Tree<T, Func>::Segment_Tree(Itr, Itr, Func, T)':
a.cc:34:25: error: 'bottom_size' was not declared in this scope
   34 |                         bottom_size = 1;
      |                         ^~~~~~~~~~~
a.cc: In member function 'void Jin::Segment_Tree<T, Func>::update(size_t, int)':
a.cc:46:30: error: 'bottom_size' was not declared in this scope
   46 |                         i += bottom_size - 1;
      |                              ^~~~~~~~~~~
a.cc: In member function 'T Jin::Segment_Tree<T, Func>::get(size_t, size_t) const':
a.cc:55:48: error: 'bottom_size' was not declared in this scope
   55 |                         return get(l, r, 0, 0, bottom_size);
      |                                                ^~~~~~~~~~~
a.cc: In member function 'void Jin::Segment_Tree<T, Func>::show() const':
a.cc:59:52: error: 'bottom_size' was not declared in this scope
   59 |                         for (size_t i = 0; i < 2 * bottom_size - 1; ++i) {
      |                                                    ^~~~~~~~~~~
a.cc: In instantiation of 'Jin::Segment_Tree<T, Func>::Segment_Tree(Itr, Itr, Func, T) [with Itr = __gnu_cxx::__normal_iterator<int*, std::vector<int> >; T = int; Func = main()::<lambda(int, int)>]':
a.cc:69:10:   required from '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)>]'
   69 |                 return Segment_Tree<T, Func>(first, last, func, init);
      |                        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:87:35:   required from here
   87 |         auto seg = Jin::make_segment_tree(AC.begin(), AC.end(), [](int a, int b) {return a + b; }, 0);
      |                    ~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:32:73: error: use of deleted function 'main()::<lambda(int, int)>::<lambda>()'
   32 |                 Segment_Tree(Itr first, Itr last, Func func, T invalid) {
      |                                                                         ^
a.cc:87:66: note: a lambda closure type has a deleted default constructor
   87 |         auto seg = Jin::make_segment_tree(AC.begin(), AC.end(), [](int a, int b) {return a + b; }, 0);
      |                                                                  ^
a.cc:32:73: note: use '-fdiagnostics-all-candidates' to display considered candidates
   32 |                 Segment_Tree(Itr first, Itr last, Func func, T invalid) {
      |                                                                         ^