Under construction

Still being built. Things may change

Intersegment Activation

Time limit2sMemory limit1024 MB

Summary
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 nn cells, numbered from 11 to nn. For each pair of integers (i,j)(i, j) with 1≤i≤j≤n1 \le i \le j \le n, there is a barrier covering all cells from ii to jj, 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, (1,2)(1, 2) and (2,3)(2, 3), are active. Together they cover all three cells, so kk is 00 in the first round.

  • After flipping barrier (2,2)(2, 2), there are three active barriers, and still 00 visible cells, so kk is 00.
  • After flipping barrier (1,2)(1, 2), cell 11 becomes visible, so kk is 11.
  • After flipping barrier (2,3)(2, 3), cell 33 also becomes visible. The only invisible cell is cell 22, covered by the only active barrier (2,2)(2, 2), so kk is 22.
  • After flipping barrier (2,2)(2, 2), all barriers are inactive and all cells are visible. After reading k=3k = 3, the program terminates.

Examples1

  1. Example 1

    Input
    3
    0
    
    0
    
    1
    
    2
    
    3
    
    Expected output
    
    
    2 2
    
    2 3
    
    1 2
    
    2 2