https://codeforces.com/problemset/problem/243/A It would be a great help if someone could explain the editorial of this question. I have been trying to understand it for a long time but simply couldn't. Thanks in advance ;) asked 12 Dec '18, 23:06

Consider all values $f(l, r)$ with fixed $r$. Claim: the number of such values is at most $20$. Let's say you maintain a set of values $f(l, r)$ for some $r$. This is quite doable because of the $20$ value limit. Let's call this set $g(r)$. Then, $g(r) = \{a_r\} \cup \{a_r \  \ x : x \in g(r1) \}$, which basically means that you OR $a_r$ with each value of $g(r1)$ to get the values of $g(r)$ and also consider the value $a_r$ itself. I suppose this can be considered dynamic programming. If you calculate $g(i)$ for all indices, the set of all possible values $f(l,r)$ is $\bigcup_{i=1}^n g(i)$. You just need to output the size of this set. answered 12 Dec '18, 23:48
thanks a lot @meooow for such a good explanation. Although, I have used a different approach ( prefix sum and binary search) and it gave me ACCEPTED ;)
(13 Dec '18, 01:50)
Could you share your approach? I'm interested to know.
(14 Dec '18, 20:46)
