You are given an array A of N integers.
Create another array B containing all or-subarrays of A . i.e B contains $$$A_{l}|A_{l+1}|...A_{r}$$$ for all $$$1 \lt = l \lt = r \lt = N$$$
You are provided Q queries . n each query you have to print K-th smallest element of B.
$$$1 \lt = A_{i} \lt = 10^{5}$$$ $$$1 \lt = Q , N \lt = 10^{5}$$$ $$$1 \lt = k \lt = N*(N+1)/2$$$
Example
N = 3 A = [1, 2, 3] Q = 3 Queries = [1, 2, 6]
B = {1, (1|2), (1|2|3), 2, (2|3), 3} = {1, 3, 3, 2, 3, 3}
The queries are answered below
• The 1st smallest element is 1
• The 2nd smallest element is 2
• The 6th smallest element is 3.
Full text and comments »