AtCoder Grand Contest 020
D
Min Max Repetition
AtCoder
⌀ 3062
原题
← CE →
翻译中…

Problem Statement

翻译中…

Let $f(A, B)$, where $A$ and $B$ are positive integers, be the string satisfying the following conditions:

翻译中…
  • $f(A, B)$ has length $A + B$;
  • $f(A, B)$ contains exactly $A$ letters A and exactly $B$ letters B;
  • The length of the longest substring of $f(A, B)$ consisting of equal letters (ex., AAAAA or BBBB) is as small as possible under the conditions above;
  • $f(A, B)$ is the lexicographically smallest string satisfying the conditions above.
翻译中…

For example, $f(2, 3)$ = BABAB, and $f(6, 4)$ = AABAABAABB.

翻译中…

Answer $Q$ queries: find the substring of $f(A_i, B_i)$ from position $C_i$ to position $D_i$ (1-based).

翻译中…

Constraints

翻译中…
  • $1 \leq Q \leq 10^3$
  • $1 \leq A_i, B_i \leq 5 \times 10^8$
  • $1 \leq C_i \leq D_i \leq A_i + B_i$
  • $D_i - C_i + 1 \leq 100$
  • All input values are integers.
翻译中…

Partial Score

翻译中…
  • $500$ points will be awarded for passing the testset satisfying $1 \leq A_i, B_i \leq 10^3$.
翻译中…

Input

翻译中…

Input is given from Standard Input in the following format:

翻译中…

Q
A_1 B_1 C_1 D_1
A_2 B_2 C_2 D_2
:
A_Q B_Q C_Q D_Q

翻译中…

Output

翻译中…

For each query $i$ in order of input, print a line containing the substring of $f(A_i, B_i)$ from position $C_i$ to position $D_i$ (1-based).

翻译中…

样例

Input #1
5
2 3 1 5
6 4 1 10
2 3 4 4
6 4 3 7
8 10 5 8
Output #1
BABAB
AABAABAABB
A
BAABA
ABAB
题目信息
题号
agc020_d
时间限制
2 s
内存限制
512 MB

题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。