Distinct OR values of subarrays
For every contiguous subarray, take the bitwise OR of its elements. How many different values do you get?
Reported in: TCS NQT (29 Apr 2024) (memory-based)
Input
First line: N. Second line: N integers.
Output
The number of distinct OR values.
Constraints
1 ≤ N ≤ 10^5; 0 ≤ values ≤ 10^9.
Example 1
Input:
4
1 2 3 2
Output:
3Example 2
Input:
3
1 2 4
Output:
6Example 3
Input:
3
0 0 0
Output:
1Hint: Keep the set of OR values of subarrays that end at the current element. Extending them by the next element can only add bits, so the set never has more than about 30 values; add each set to a global set.