#P10743. Good Array Partition
Good Array Partition
Good Array Partition
An array \( b = [b_1, b_2, \dots, b_n] \) is called a good array if and only if it can be partitioned into two non-empty contiguous subarrays such that the bitwise \( \operatorname{OR} \) of the first part and the bitwise \( \operatorname{AND} \) of the second part are equal. In other words, there exists an index \( k \) with \( 1 \le k < n \) such that:
[ \operatorname{OR}(b_1, b_2, \dots, b_k) = \operatorname{AND}(b_{k+1}, b_{k+2}, \dots, b_n). ]
You are given an array \( a \) of length \( n \) and \( q \) queries. In each query you are given a range \( [l, r] \); you need to determine whether the subarray \( [a_l, a_{l+1}, \dots, a_r] \) is a good array.
inputFormat
The first line contains a single integer \( n \) \( (1 \le n \le 10^5) \), the size of the array \( a \). The second line contains \( n \) space-separated integers \( a_1, a_2, \dots, a_n \). The third line contains an integer \( q \) \( (1 \le q \le 10^5) \), the number of queries. Each of the next \( q \) lines contains two integers \( l \) and \( r \) \( (1 \le l < r \le n) \), representing a query on the subarray \( [a_l, a_{l+1}, \dots, a_r] \).
outputFormat
For each query, output a single line containing YES
if the subarray is a good array, or NO
otherwise.
sample
4
1 7 3 11
1
1 4
YES