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 main(){
	cin>>q;
	rep(w,q){
		ll a,b,c,d;
		cin>>a>>b>>c>>d;
		ll lb = -1,ub = 1e9+5;
		while(ub-lb > 1){
			ll mid = (lb+ub)/2;
			if(a*mid+mid>=b && b*mid+mid>=a) ub = mid;
			else lb = mid;
		}
		ll cnt = ub;
		lb=0,ub=a+b+1;
		while(ub-lb > 1){
			ll mid = (lb+ub)/2;
			ll bcnt = mid/(cnt+1);
			ll acnt = mid-bcnt;
			acnt += (a+b-mid)/(cnt+1);
			bcnt += (a+b-mid)-(a+b-mid)/(cnt+1);
			if(acnt > a) ub=mid;
			else lb = mid;
		}
		for(ll x=max(0,lb-334LL);x<=min(a+b,lb+334LL);x++){
			ll bcnt = x/(cnt+1);
			ll acnt = x-bcnt;
			acnt += (a+b-x)/(cnt+1);
			bcnt += (a+b-x)-(a+b-x)/(cnt+1);
			if(acnt != a || bcnt != b) continue;
			for(ll i=c;i<=d;i++){
				if(i<=x){
					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");
				}
			}
			puts("");
			break;
		}
	}
}


Compiler output:
a.cc: In function 'int main()':
a.cc:22:14: error: 'q' was not declared in this scope
   22 |         cin>>q;
      |              ^
a.cc:43:29: error: no matching function for call to 'max(int, ll)'
   43 |                 for(ll x=max(0,lb-334LL);x<=min(a+b,lb+334LL);x++){
      |                          ~~~^~~~~~~~~~~~
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:43:29: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'll' {aka 'long long int'})
   43 |                 for(ll x=max(0,lb-334LL);x<=min(a+b,lb+334LL);x++){
      |                          ~~~^~~~~~~~~~~~
/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:43:29: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   43 |                 for(ll x=max(0,lb-334LL);x<=min(a+b,lb+334LL);x++){
      |                          ~~~^~~~~~~~~~~~