Language: C++

#include<iostream>
#include<vector>
#include<array>
#include<string>
#include<map>

struct mod
{
	std::uint64_t val;
	void operator+=(std::uint64_t v)
	{
		val += v;
		val %= 1000000007;
	}
	void operator+=(mod v)
	{
		val += v.val;
		val %= 1000000007;
	}
	void operator*=(std::uint64_t v)
	{
		val *= v;
		val %= 1000000007;
	}
	void operator*=(mod v)
	{
		val *= v.val;
		val %= 1000000007;
	}

};

mod operator*(mod x, mod y)
{
	x *= y;
	return x;
}
mod operator+(mod x, mod y)
{
	x += y;
	return x;
}
mod operator*(mod x, int y)
{
	x *= y;
	return x;
}
mod operator+(mod x, int y)
{
	x += y;
	return x;
}
mod operator*(int y, mod x)
{
	x *= y;
	return x;
}
mod operator+(int y, mod x)
{
	x += y;
	return x;
}

struct data
{
	std::map<int, int> starts;
	data(std::string const& str) :starts{}
	{
		char c = str.front();
		if (c == 'A')
		{
			starts[0] = 1;
		}
		else
		{
			starts[0] = 0;
		}
		for (std::size_t i = 1; i < str.size(); ++i)
		{
			if (c == 'A')
			{
				if (str[i] == 'A')
				{
					++starts.rbegin()->second;
				}
				else
				{
					c = 'B';
				}
			}
			else
			{
				if (str[i] == 'A')
				{
					starts[i] = 1;
				}
			}
		}
		starts[str.size()] = 0;
		
	}
	int get_cat(int start, int last)
	{
		auto ite = std::upper_bound(starts.begin(), starts.end(), std::pair<decltype(starts.begin()->first), int>(start, std::numeric_limits<int>::max()));
		int cat{};
		while (start != last)
		{
			auto prev = std::prev(ite);
			int m = prev->first + prev->second;
			int e = std::min(ite->first, last);
			int a = std::max(m - start, 0) % 3;
			int b = std::min(e - start, e - m) % 3;
			cat += a + 2 * b;
			cat %= 3;
			start = e;
			++ite;
		}
		return cat;
	}
};

int main()
{
	std::string str;
	std::cin >> str;
	data from{ str };
	std::cin >> str;
	data to{ str };
	int q;
	std::cin >> q;
	for (int i{}; i < q; ++i)
	{
		int a, b, c, d;
		std::cin >> a >> b >> c >> d;
		--a;
		--c;
		if (from.get_cat(a, b) == to.get_cat(c, d))
		{
			std::cout << "YES" << std::endl;
		}
		else
		{
			std::cout << "NO" << std::endl;
		}
	}
}

Compiler output:
a.cc:9:14: error: 'uint64_t' in namespace 'std' does not name a type; did you mean 'wint_t'?
    9 |         std::uint64_t val;
      |              ^~~~~~~~
      |              wint_t
a.cc:10:25: error: 'std::uint64_t' has not been declared
   10 |         void operator+=(std::uint64_t v)
      |                         ^~~
a.cc:20:25: error: 'std::uint64_t' has not been declared
   20 |         void operator*=(std::uint64_t v)
      |                         ^~~
a.cc: In member function 'void mod::operator+=(int)':
a.cc:12:17: error: 'val' was not declared in this scope
   12 |                 val += v;
      |                 ^~~
a.cc: In member function 'void mod::operator+=(mod)':
a.cc:17:17: error: 'val' was not declared in this scope
   17 |                 val += v.val;
      |                 ^~~
a.cc:17:26: error: 'struct mod' has no member named 'val'
   17 |                 val += v.val;
      |                          ^~~
a.cc: In member function 'void mod::operator*=(int)':
a.cc:22:17: error: 'val' was not declared in this scope
   22 |                 val *= v;
      |                 ^~~
a.cc: In member function 'void mod::operator*=(mod)':
a.cc:27:17: error: 'val' was not declared in this scope
   27 |                 val *= v.val;
      |                 ^~~
a.cc:27:26: error: 'struct mod' has no member named 'val'
   27 |                 val *= v.val;
      |                          ^~~
a.cc: In member function 'int data::get_cat(int, int)':
a.cc:104:33: error: 'upper_bound' is not a member of 'std'; did you mean 'lower_bound'?
  104 |                 auto ite = std::upper_bound(starts.begin(), starts.end(), std::pair<decltype(starts.begin()->first), int>(start, std::numeric_limits<int>::max()));
      |                                 ^~~~~~~~~~~
      |                                 lower_bound
a.cc:104:135: error: 'numeric_limits' is not a member of 'std'
  104 |                 auto ite = std::upper_bound(starts.begin(), starts.end(), std::pair<decltype(starts.begin()->first), int>(start, std::numeric_limits<int>::max()));
      |                                                                                                                                       ^~~~~~~~~~~~~~
a.cc:104:122: error: expected primary-expression before '(' token
  104 |                 auto ite = std::upper_bound(starts.begin(), starts.end(), std::pair<decltype(starts.begin()->first), int>(start, std::numeric_limits<int>::max()));
      |                                                                                                                          ^
a.cc:104:135: error: 'numeric_limits' is not a member of 'std'
  104 |                 auto ite = std::upper_bound(starts.begin(), starts.end(), std::pair<decltype(starts.begin()->first), int>(start, std::numeric_limits<int>::max()));
      |                                                                                                                                       ^~~~~~~~~~~~~~
a.cc:104:150: error: expected primary-expression before 'int'
  104 |                 auto ite = std::upper_bound(starts.begin(), starts.end(), std::pair<decltype(starts.begin()->first), int>(start, std::numeric_limits<int>::max()));
      |                                                                                                                                                      ^~~