Intersegment Activation
Time limit2sMemory limit1024 MB
Interactive task: flip interval barriers one at a time, reading the visible-cell count after each flip, until every barrier is inactive.
- Level
Hard8 of 10
- Topics
- Bit manipulation, Math, Implementation
- Solved
- No attempts yet
Statement
This is an interactive problem.
There is an array of cells, numbered from to . For each pair of integers with , there is a barrier covering all cells from to , inclusive. Each barrier is either active or inactive. A cell is visible if no active barrier covers it. Otherwise, the cell is invisible.
The state of each barrier is unknown to you. You can only observe the number of visible cells. You can flip the state of any barrier: an active barrier becomes inactive, and an inactive barrier becomes active. Your task is to make all barriers inactive, so that all cells become visible.
Hint

In the example, initially only two barriers, and , are active. Together they cover all three cells, so is in the first round.
- After flipping barrier , there are three active barriers, and still visible cells, so is .
- After flipping barrier , cell becomes visible, so is .
- After flipping barrier , cell also becomes visible. The only invisible cell is cell , covered by the only active barrier , so is .
- After flipping barrier , all barriers are inactive and all cells are visible. After reading , the program terminates.