Official algorithmic problem description and constraints.
Today, Cat and Fox found an array π consisting of π non-negative integers.
Define the loneliness of π as the smallest positive integer π (1β€πβ€π) such that for any two positive integers π and π (1β€π,πβ€πβπ+1), the following holds:
ππ|ππ+1|β¦|ππ+πβ1=ππ|ππ+1|β¦|ππ+πβ1,
where π₯|π¦ denotes the bitwise OR of π₯ and π¦. In other words, for every π consecutive elements, their bitwise OR should be the same. Note that the loneliness of π is well-defined, because for π=π the condition is satisfied.Cat and Fox want to know how lonely the array π is. Help them calculate the loneliness of the found array.
Detailed video explanations, mathematical intuition, and clean C++ implementation code.