Logo
(追記) (追記ここまで)

20755번 - Fix the heap 32-bit 다국어인터랙티브

시간 제한메모리 제한제출정답맞힌 사람정답 비율
13 초 256 MB316526.316%

문제

Petya wrote a heap for dynamic memory allocation in his own programming language Tse. Here is how it works.

A correct heap is a continuous segment of memory consisting of $N$ cells. Each cell contains an unsigned 32-bit integer, which can have any value from 0 to $\mathbf{4,294円,967円,295円}$ inclusive. The heap is split into $B$ sub-segments called blocks. Each of the memory cells belongs to strictly one block.

Each block consists of two or more cells. The first and the last cells of a block contain the effective size of the block, which is the number of cells in it, excluding the first and last cells. The rest of the block's cells can contain arbitrary data regardless of whether the block is free or occupied.

Tse is a very low-level language, and its users often mess everything up and corrupt the heap by inadvertently writing their data into wrong cell. Users are asking Petya to come up with a feature of recovering heap integrity after such incidents. The recovery code must analyze the contents of $N$ cells of the memory segment where the heap is supposed to be located, and change the contents of several memory cells in such a manner that the segment becomes a correct heap. The number of modified cells must be minimal.

입력

출력

제한

프로토콜

The number of memory cells can be very large, and your program won't be able to read the whole segment. For this reason, this is an interactive task. Instead of file input-output, you will be working with a special program called interactor. Interaction with this program is performed by means of the standard input-output streams.

At the start, your program receives an integer $N$ in the standard input stream, being the number of memory cells in the analyzed segment (2ドル \le N \le 2^{32}$). Next, your program can make queries to discover the contents of various memory cells. To make a query, print the word read into the standard output stream, followed by a space-separated integer $A,ドル being the address/index of the cell (0ドル \le A < N$). In response, a single integer $V$ will be sent to the standard input stream, being the value stored in the $A$-th memory cell (0ドル \le V < 2^{32}$).

Eventually, your program must print the answer to the problem instead of yet another query. In the first line of the answer, print the word fix, followed by a space-separated integer $K,ドル being the number of cells that must be changed ($K \ge 0$). In the remaining $K$ lines, print the suggested changes, one per line. For each change, print two integers: $A$ being address/index of the cell that must be changed and $V$ being new value written into this cell (0ドル \le A < N,ドル 0ドル \le V < 2^{32}$).

It is guaranteed that there exists an optimal answer resulting in a heap with no more than 25ドル,000円$ blocks. Your program is allowed to make no more than 120ドル,000円$ queries, otherwise the solution will get \textsf{Wrong Answer}.

Make sure you print the end-of-line symbol and clear the output stream buffer (the flush command of the language) after every printed query. Otherwise the solution can get \textsf{Timeout}. All numbers are written in decimal form in text format.

예제 입력 1

11
2
170
187
204
0
221
3
171
172
173
3

예제 출력 1

read 0
read 1
read 2
read 3
read 4
read 5
read 6
read 7
read 8
read 9
read 10
fix 2
3 2
5 0

힌트

The example fully repeats the second example from another problem <<Fix the heap 8bit>>: both the contents of the memory cells and the suggested recovery fixes are the same. Illustration:

출처

Contest > Open Cup > 2020/2021 Season > Stage 1: XXI All-Siberian Programming Contest 5번

채점 및 기타 정보

  • 예제는 채점하지 않는다.
(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /