QOJ.ac

QOJ

実行時間制限: 4 s メモリ制限: 512 MB 満点: 100 インタラクティブ

#10372. Xiao Xiu and Xiao Dong Guess Numbers

統計

This is an interactive problem.

Xiao Xiu and Xiao Dong like to play a game called "Guess the Number."

Xiao Xiu first thinks of a sequence $a_1, a_2, \dots, a_n$ consisting of $n$ distinct positive integers.

In each turn, Xiao Dong asks Xiao Xiu for the median of $a_x, a_y, a_z$, and Xiao Xiu answers accurately. Xiao Dong then needs to use this information to reconstruct the sequence $a$ as accurately as possible.

However, Xiao Xiu is so skilled that the chosen $n$ is always very large, leaving Xiao Dong unsure of how to proceed.

Please help Xiao Dong so he can play happily with Xiao Xiu.

Interaction

You need to implement a function guess() to help Xiao Dong complete the game.

  • guess(n)
    • n is the length of the sequence.

In each test case, the interactor will call the guess() function exactly once.

You can call the function ask() to query Xiao Xiu. Your score will be based on the total number of times you call this function.

  • ask(x, y, z)
    • x, y, z are three distinct indices.
    • This function returns the median of $a_x, a_y, a_z$.

Additionally, you can call the function answer() to provide the information you have reconstructed.

  • answer(x, v)
    • x is the index of the reconstructed number.
    • v is the value of $a_x$ you reconstructed.

You cannot call answer() twice for the same index $x$, but you may choose not to call it for some $x$, which indicates that you were unable to reconstruct the value at that index.

Implementation Details

Your source code must include the header file guess.h.

The function guess() you need to implement is:

void guess(int n);

The interface for the function ask() is:

int ask(int x, int y, int z);

The interface for the function answer() is:

void answer(int x, int v);

How to Test Your Program

You need to compile your program using the following command in the problem directory to obtain an executable:

g++ -o guess grader.cpp guess.cpp -O2

The executable will read data from standard input in the following format:

The first line contains a positive integer $n$, where $n \leq 10^5$.

The second line contains $n$ positive integers $a_1, a_2, \dots, a_n$, where all $a_i$ are distinct and $0 < a_i \leq 10^9$.

After reading the input, the interactor will call the guess() function.

The interactor will then output the following information to standard output:

The first line contains $n$ integers $b_1, b_2, \dots, b_n$, representing the sequence you reconstructed, where $b_i = -1$ indicates that you did not reconstruct the value at that index.

The second line is in the format Count: cnt, where cnt is the number of times you called the ask() function.

Sample Source Code

In the problem directory, there is a sample source code guess.cpp in C++. Compiling it as described above will produce an executable.

The sample source code is only provided to help you understand the problem; the results it produces are not necessarily correct.

Input

(See the "How to Test Your Program" section)

Output

(See the "How to Test Your Program" section)

Examples

Input 1

3
1 2 3

Output 1

1 2 3
Count: 1

Note 1

This is the output file obtained using the grader and the sample source code provided in the problem directory.

Subtasks

For each test case, we will compare your results with those of the reference solution. If the reconstructed sequence is inconsistent, you will receive 0 points. Otherwise, let $Y$ and $S$ be the number of times you and the reference solution called the ask() function, respectively. If $Y \leq S$, your score ratio is $100\%$; otherwise, your score ratio is $(10 \cdot 2^{4-\frac{Y}{S}}+20)\%$.

For each subtask, your score will be the minimum score obtained across all test cases in that subtask, multiplied by the subtask's total points.

Subtask 1 (20 points): $n \leq 10$.

Subtask 2 (20 points): $n \leq 100$.

Subtask 3 (20 points): $n \leq 2000$.

Subtask 4 (40 points): $n \leq 100000$.

Please note that the guess.h used for final evaluation is different from the one provided.

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.