Language: C++

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

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:11:14: error: 'uint64_t' in namespace 'std' does not name a type; did you mean 'wint_t'?
   11 |         std::uint64_t val;
      |              ^~~~~~~~
      |              wint_t
a.cc:12:25: error: 'std::uint64_t' has not been declared
   12 |         void operator+=(std::uint64_t v)
      |                         ^~~
a.cc:22:25: error: 'std::uint64_t' has not been declared
   22 |         void operator*=(std::uint64_t v)
      |                         ^~~
a.cc: In member function 'void mod::operator+=(int)':
a.cc:14:17: error: 'val' was not declared in this scope
   14 |                 val += v;
      |                 ^~~
a.cc: In member function 'void mod::operator+=(mod)':
a.cc:19:17: error: 'val' was not declared in this scope
   19 |                 val += v.val;
      |                 ^~~
a.cc:19:26: error: 'struct mod' has no member named 'val'
   19 |                 val += v.val;
      |                          ^~~
a.cc: In member function 'void mod::operator*=(int)':
a.cc:24:17: error: 'val' was not declared in this scope
   24 |                 val *= v;
      |                 ^~~
a.cc: In member function 'void mod::operator*=(mod)':
a.cc:29:17: error: 'val' was not declared in this scope
   29 |                 val *= v.val;
      |                 ^~~
a.cc:29:26: error: 'struct mod' has no member named 'val'
   29 |                 val *= v.val;
      |                          ^~~
a.cc: In member function 'int data::get_cat(int, int)':
a.cc:106:33: error: 'upper_bound' is not a member of 'std'; did you mean 'lower_bound'?
  106 |                 auto ite = std::upper_bound(starts.begin(), starts.end(), std::pair<decltype(starts.begin()->first), int>(start, std::numeric_limits<int>::max()));
      |                                 ^~~~~~~~~~~
      |                                 lower_bound