Language: C++

#include <bits/stdc++.h>
using namespace std;
#define int long long
int n , a , b , l , r , len , rb , ra , e , Ra , rem;
#define putchar('A') Y
#define putchar('B') N
void doit(int a , int b , int len , int l , int r) {
    int L = 0 , R = a / len , ans = -1;
    while(L <= R) {
	int mid = (L + R) >> 1 , res = 0;
	res = (b - mid + 1) / (a - mid * len + 1); if((b - mid + 1) % (a - mid * len + 1) != 0) ++ res;
	if(res > len)  R = mid - 1; else L = mid + 1 , ans = mid;
    }
    for(int i = l;i <= min(r , ans * (len + 1) - 1);++ i) if(i % (len + 1) == 0) N; else Y;
    if(r < ans * (len + 1)) return;
    l = max(l , ans * (len + 1));
    rb = b-(ans - 1),ra=a-ans * len;e = ans * (len + 1);
    if(l == e) {
	++ l; N; if(l > r) return;
    }
    ++ e;-- rb;
    Ra = rb / len + (rb % len != 0) - 1;
    e = e + ra - Ra;
    for(int i = l;i <= min(r , e - 1);++ i) Y;
    l = max(l,e); ra = Ra; if (l> r) return;
    rem = len - ((ra + 1) * len - rb);
    for(int i = l;i <= r;++ i) if(i < rem + e) N;else if(i % (len + 1) == (rem+e) % (len + 1)) Y; else N;
}

main(void) {
    for(cin >> n;n--;) {
	cin >> a >> b >> l >> r;
	if(a > b) len = (a / (b + 1)) + (a % (b + 1) != 0);else len = b / (a + 1) + (b % (a + 1) != 0);doit(a , b , len , l , r);puts("");
    }
}


Compiler output:
a.cc:5:17: error: expected parameter name, found "'A'"
    5 | #define putchar('A') Y
      |                 ^~~
a.cc:6:17: error: expected parameter name, found "'B'"
    6 | #define putchar('B') N
      |                 ^~~
a.cc: In function 'void doit(long long int, long long int, long long int, long long int, long long int)':
a.cc:14:82: error: 'N' was not declared in this scope
   14 |     for(int i = l;i <= min(r , ans * (len + 1) - 1);++ i) if(i % (len + 1) == 0) N; else Y;
      |                                                                                  ^
a.cc:14:90: error: 'Y' was not declared in this scope
   14 |     for(int i = l;i <= min(r , ans * (len + 1) - 1);++ i) if(i % (len + 1) == 0) N; else Y;
      |                                                                                          ^
a.cc:19:15: error: 'N' was not declared in this scope
   19 |         ++ l; N; if(l > r) return;
      |               ^
a.cc:24:45: error: 'Y' was not declared in this scope
   24 |     for(int i = l;i <= min(r , e - 1);++ i) Y;
      |                                             ^
a.cc:27:48: error: 'N' was not declared in this scope
   27 |     for(int i = l;i <= r;++ i) if(i < rem + e) N;else if(i % (len + 1) == (rem+e) % (len + 1)) Y; else N;
      |                                                ^
a.cc:27:96: error: 'Y' was not declared in this scope
   27 |     for(int i = l;i <= r;++ i) if(i < rem + e) N;else if(i % (len + 1) == (rem+e) % (len + 1)) Y; else N;
      |                                                                                                ^
a.cc:27:104: error: 'N' was not declared in this scope
   27 |     for(int i = l;i <= r;++ i) if(i < rem + e) N;else if(i % (len + 1) == (rem+e) % (len + 1)) Y; else N;
      |                                                                                                        ^
a.cc: At global scope:
a.cc:30:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   30 | main(void) {
      | ^~~~