Language: C++

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
int q;
int main(){
	cin>>q;
	rep(w,q){
		ll a,b,c,d;
		cin>>a>>b>>c>>d;
		ll k = (a+b)/(min(a,b)+1);
		ll lb=0,ub=a+1;
		while(ub-lb > 1){
			ll mid = (lb+ub)/2;
			ll bb = max(0,(mid-1)/k);
			ll zana = a-mid,zanb - b-bb;
			if(zanb <= (zana+1)*k){
				lb = mid;
			}
			else{
				ub = mid;
			}
		}
		bool ok = 0;
		for(ll x=max(0LL,lb-334LL);x<=min(a+b,lb+334LL);x++){
			ll acnt = x
			ll bcnt = max(0,(x-1)/k);
			ll sum = acnt+bcnt;
			acnt += (a+b-sum)/(k+1);
			bcnt += (a+b-sum)-(a+b-sum)/(k+1);
			if(acnt != a || bcnt != b) continue;
			for(ll i=c;i<=d;i++){
				if(i<=sum){
					if(i%(cnt+1) == 0) printf("B");
					else printf("A");
				}
				else{
					ll j = a+b+1-i;
					if(j%(cnt+1) == 0) printf("A");
					else printf("B");
				}
			}
			ok = 1;
			puts("");
			break;
		}
		assert(ok);
	}
}

Compiler output:
a.cc: In function 'int main()':
a.cc:31:36: error: no matching function for call to 'max(int, ll)'
   31 |                         ll bb = max(0,(mid-1)/k);
      |                                 ~~~^~~~~~~~~~~~~
In file included from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:   template argument deduction/substitution failed:
a.cc:31:36: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'll' {aka 'long long int'})
   31 |                         ll bb = max(0,(mid-1)/k);
      |                                 ~~~^~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note:   candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/14/algorithm:61:
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5706 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
 5716 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note:   template argument deduction/substitution failed:
a.cc:31:36: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   31 |                         ll bb = max(0,(mid-1)/k);
      |                                 ~~~^~~~~~~~~~~~~
a.cc:32:46: error: expected initializer before '-' token
   32 |                         ll zana = a-mid,zanb - b-bb;
      |                                              ^
a.cc:33:28: error: 'zanb' was not declared in this scope; did you mean 'zana'?
   33 |                         if(zanb <= (zana+1)*k){
      |                            ^~~~
      |                            zana
a.cc:43:25: error: expected ',' or ';' before 'll'
   43 |                         ll bcnt = max(0,(x-1)/k);
      |                         ^~
a.cc:44:39: error: 'bcnt' was not declared in this scope; did you mean 'acnt'?
   44 |                         ll sum = acnt+bcnt;
      |                                       ^~~~
      |                                       acnt
a.cc:50:47: error: 'cnt' was not declared in this scope; did you mean 'acnt'?
   50 |                                         if(i%(cnt+1) == 0) printf("B");
      |                                               ^~~
      |                                               acnt
a.cc:55:47: error: 'cnt' was not declared in this scope; did you mean 'acnt'?
   55 |                                         if(j%(cnt+1) == 0) printf("A");
      |                                               ^~~
      |                                               acnt