Codeforces Round 1026 (Div. 2)
F
Faculty
Codeforces
2400
原题
← E→
翻译中…

In 2077, after the world was enslaved by robots, the robots decided to implement an educational reform, and now the operation of taking the modulus is only taught in the faculty of "Ancient World History". Here is one of the entrance tasks for this faculty:

翻译中…

We define the beauty of an array of positive integers $b$ as the maximum $f(b_i, b_j)$ over all pairs $1 \leq i, j \leq n$, where $f(x, y) = (x \bmod y) + (y \bmod x)$.

翻译中…

Given an array of positive integers $a$ of length $n$, output $n$ numbers, where the $i$-th number ($1 \leq i \leq n$) is the beauty of the array $a_1, a_2, \ldots, a_i$.

翻译中…

$x \bmod y$ is the remainder of the division of $x$ by $y$.

翻译中…

Input

翻译中…

Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10^4$). The description of the test cases follows.

翻译中…

The first line of each test case contains a single integer $n$ ($1 \leq n \leq 10^6$) — the size of the array $a$.

翻译中…

The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \leq a_i \leq 10^9$).

翻译中…

It is guaranteed that the sum of $n$ across all test cases does not exceed $10^6$.

翻译中…

Output

翻译中…

For each test case, output $n$ integers — the beauties of all prefixes of the array $a$.

翻译中…

Note

翻译中…

The beauty of the array $3$ is $0$.

翻译中…

The beauty of the array $3, 1$ is $f(3, 1) = 1$.

翻译中…

The beauty of the array $3, 1, 4$ is $f(3, 4) = 4$.

翻译中…

The beauty of the array $3, 1, 4, 1$ is $f(4, 3) = 4$.

翻译中…

The beauty of the array $3, 1, 4, 1, 5$ is $f(4, 5) = 5$.

翻译中…

样例

Input #1
2
5
3 1 4 1 5
7
5 11 11 4 2 1 10
Output #1
0 1 4 4 5
0 6 6 7 7 7 11
InputCopy OutputCopy
题目信息
题号
2110F
时间限制
2 s
内存限制
256 MB
标签
暴力
贪心
数学
数论

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