P16565 [CodeChef] MAXDMGE
提高-
题目描述

Nasir and two of his henchmen are planning to attack N shops of the Qureshi clan. The shops are conveniently lined up, and numbered from 1 to N. The i-th shop contains A_{i} kg of coal.

For a given subarray of shops $[A_{L}, A_{L+1}, \dots, A_{R}]$, the bitwise and of this subarray is defined to be the [bitwise AND] of the coal contained in each of the shops, i.e, A_{L} \& A_{L+1} \& $\dots$ \& A_{R}.

The damage caused when bombing the i-th shop is computed to be the maximum bitwise and over all subarrays containing shop i, and whose size is strictly larger than 1.

For each shop (1≤ i≤ N), find the damage caused when Nasir bombs it.

------ Input Format ------

  • The first line of input contains a single integer T denoting the number of test cases. The description of T test cases follows.
  • The first line of each test case contains a single integer N, denoting the number of shops.
  • The second line of each test case contains N space-separated integers, the i-th of which is A_{i}, representing the amount of coal in the i-th shop.

------ Output Format ------

For each test case, print $a single line containing N integers d_{1},d_{2},\ldots,d_{n}$ where d_{i} represents the maximum damage that can be caused if the i-th shop is to be bombed.

------ Constraints ------

$1 ≤ T ≤ 10000$
$2 ≤ N ≤ 2 \cdot 10^{5}$
$0 ≤ A_{i} ≤ 10^{9}$
- The sum of $N$ over all test cases does not exceed $2 \cdot 10^{5}$.

----- Sample Input 1 ------
2
5
29 412 671 255 912
6
166 94 184 114 1124 298
----- Sample Output 1 ------
28 156 159 159 144
6 24 48 96 96 32

----- explanation 1 ------
Test case 1: There are several choices of subarray which give the maximum for each index. One such choice is given below:

For shop $1$, choose subarray $[29, 412, 671, 255]$

For shop $2$, choose subarray $[412, 671, 255]$

For shop $3$, choose subarray $[671, 255]$

For shop $4$. choose subarray $[671, 255]$

For shop $5$, choose subarray $[412, 671, 255, 912]$

输入格式

见题面

输出格式

见题面

样例输入
2 5 29 412 671 255 912 6 166 94 184 114 1124 298
样例输出
28 156 159 159 144 6 24 48 96 96 32