AND & OR & max on a segment#4504

AND & OR & max on a segment

1 second
128 megabytes
Medium

Vasyl has integers: x_1, x_2, \ldots, x_n. You must help him answer queries of two types:

  1. AND L R — find the maximum value of x_{i_1} \ \mathrm{AND} \ x_{i_2} \ \mathrm{AND} \ \ldots \ \mathrm{AND} \ x_{i_k}, where \{ x_{i_j} \} is some nonempty subset such that L \leq i_1 < i_2 < \ldots < i_k \leq R and 1 \leq L \leq R \leq n.

  2. OR L R — find the maximum value of x_{i_1} \ \mathrm{OR} \ x_{i_2} \ \mathrm{OR} \ \ldots \ \mathrm{OR} \ x_{i_k}, where \{ x_{i_j} \} is some nonempty subset such that L \leq i_1 < i_2 < \ldots < i_k \leq R and 1 \leq L \leq R \leq n.

\InputFileThe first line contains the integer (1 \leq n \leq 100\,000). The second line contains integers x_i (0 \leq x_i \leq 10^9). The third line contains the integer (1 \leq m \leq 100\,000) — the number of queries. Each of the following lines contains one query in the format described above.

\OutputFileFor each query, print the answer on a separate line.

Examples

Example 1

Loading
Loading