Given array of length n
. I need to find amount of subarrays (or amount of pairs 1 <= l <= r <= n
) such that OR(a[l], a[l+1], ..., a[r]) > max(a[l], a[l+1], ..., a[r])
for O(nlogn * T)
, where T = max(a[i])
.
My approach: we can build Sparse Table for min
and bitwise OR
to get result on the segment for O(1)
. Also I noticed that OR(a[l], a[l+1], ..., a[r]) >= max(a[l], a[l+1], ..., a[r])
, and OR(a[l], a[l+1], ..., a[r]) <= 2^(logT + 1) - 1
, and both functions are monotonically increasing when we increment R. Not sure how to do the rest…
sdfg is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.