For context please refer to https://codeforces.me/blog/entry/159248.
So the first problem i am writing about is D. Bitwise Paradox (Div. 1 D, rated 3100)
First of all, I will be honest: I mind-solved this problem while lying in bed. It was time to sleep, but I started thinking about the problem and came up with a solution right there.
For problems like this, the first thing that comes to my mind is parallel binary search, and it turns out that if there were no updates, this problem could have been solved with it. Next I thought about a segment tree, but I could not see an obvious way to combine two ranges. So I thought about something else: how to compare two numbers.
Consider this approach. Go from the highest bit (the 29th) down to the 0th. At each bit:
If the bit is set in v: set it in our current mask, then find the minimum possible maximum over all ranges that contain, for every bit in the current mask, at least one number having that bit. If this was the lowest set bit of v, update the answer. Otherwise, do not update it, since the result so far is not yet guaranteed to be at least v. If the bit is not set in v: set it in our current mask and find the same minimum maximum. Then update the answer, because all the higher bits of v are already covered and this extra bit makes the OR strictly greater than v. After updating the answer, unset this bit again.
It is easy to see that this algorithm is correct. However, there is no obvious way to compute "the minimum maximum of a range that contains at least one number for every bit in the current mask," since there can be O(N) numbers for each bit. Thinking about the segment tree again, I realized this can be done with one.
Each node of the segment tree, covering the range [L, R], stores:
The range maximum. The range answer. For every bit i, the maximum over the range [L, x], where x is the first index in the node's range whose number contains bit i. For every bit i, the maximum over the range [x, R], where x is the last index in the node's range whose number contains bit i.
With this, a node's answer is the minimum of the answers of its left and right children, together with the answer for ranges that cross the middle. For the crossing part, we repeat the exact process described above. Queries can be answered simply because max is monotonic, and we only need to go as far as the last or first position of a bit (depending on whether we are in the left or right child). Overlapping ranges do not matter, since max is idempotent.
With this, the problem is solved. Personally, I found this problem easy, and I do not know why it is rated 3100.
Since my English is not good, this blog was proofread by Claude. The ideas and the solution are my own.I wrote the whole thing on my own first then gave it to Claude.
Any advice about the blog may be shared in comments. Thanks!








Auto comment: topic has been updated by Ahmed-Nawaz (previous revision, new revision, compare).
Auto comment: topic has been updated by Ahmed-Nawaz (previous revision, new revision, compare).
may i know why the downvotes, did i do something wrong ?