#P9649. Maximize Bitwise AND Value from Intervals
Maximize Bitwise AND Value from Intervals
Maximize Bitwise AND Value from Intervals
Given \(n\) intervals \([l_1, r_1], [l_2, r_2], \dots, [l_n, r_n]\), you must choose an integer from each interval such that the bitwise AND of all the chosen integers is maximized. In other words, if you choose \(a_i\) from the \(i\)th interval \([l_i, r_i]\), you need to maximize \[ b = a_1 \land a_2 \land \cdots \land a_n \] where \(\land\) denotes the bitwise AND operation. Output the maximum possible value of \(b\).
Note: An integer \(x\) is said to satisfy the condition \(x \land M = M\) (for some mask \(M\)) if all bits set in \(M\) are also set in \(x\). This fact is used to determine if an interval can contribute the forced bits.
inputFormat
The first line contains a single integer \(n\) (the number of intervals).\
Each of the next \(n\) lines contains two integers \(l_i\) and \(r_i\) representing the endpoints of the \(i\)th interval.
outputFormat
Output a single integer representing the maximum possible bitwise AND value obtainable by selecting one integer from each interval.
sample
2
5 7
6 8
7
</p>