QOJ.ac

QOJ

時間限制: 10 s 記憶體限制: 512 MB 總分: 100 互動

#13468. Landlords

统计

This is an interactive problem.

You probably haven't seen CZL for a few months, but he is back! We have successfully put Xiao U, Xiao Z, and CZL into a single set of problems.

CZL has a shuffled deck of cards. There are $n$ cards in the deck, indexed from $0$ to $n-1$ from top to bottom. The values of the cards are a permutation of $0, 1, 2, \dots, n-1$, and all card values are distinct. Now, you need to determine the value of each card in the deck. However, how could a great magician just tell you the answer directly?

Initially, both CZL's left hand and right hand are at the position of the $0$-th card. Each time, you can instruct him to move his left hand one card up or one card down. You can also instruct him to move his right hand one card up or one card down. Additionally, you can ask him whether the card at his left hand is smaller than the card at his right hand. Through these operations, you need to determine the value of every card in the deck from top to bottom.

Although CZL's hands are very flexible, he still has to perform magic for other people. Therefore, please determine the value of each card from top to bottom using no more than $7.0 \cdot 10^8$ moves.

Your code must include the header file "lancllords.h", and you need to implement the following function:

vector<int> answer(int n);

In this function, the positive integer $n$ represents the number of cards. This function should return an array $P$ of length $n$, where P[i] represents the value of the $i$-th card from the top.

Assume CZL's left hand is at the position of the $p$-th card and his right hand is at the position of the $q$-th card. You can call the following functions:

void inc_p();

Moves CZL's left hand one card down.

void dec_p();

Moves CZL's left hand one card up.

void inc_q();

Moves CZL's right hand one card down.

void dec_q();

Moves CZL's right hand one card up.

bool cmp();

Compares the value of the card at position $p$ with the value of the card at position $q$. Returns true if the card at position $p$ is smaller than the card at position $q$, and false otherwise.

Every time you call one of the first four functions, the grader's variable $cnt$ increases by $1$. During the final evaluation, if the value of $cnt$ is too large, the test case will be considered failed. You must ensure that $0 \le p, q < n$ at all times; otherwise, the test case will also be considered failed.

Note that the interactive library will run within five seconds, provided that the number of calls to the first four functions does not exceed $7.0 \cdot 10^8$ and the number of calls to the fifth function does not exceed $10^7$. This means your code has at least five seconds of execution time.

We have provided the files grader.cpp and lancllords_sample.cpp, where lancllords_sample.cpp is an example of a participant's code. You can test your program using the command g++ lancllords.cpp grader.cpp -o lancllords -O2.

Input

The first line contains a positive integer $n$, representing the number of cards.

The next line contains $n$ integers $P_0, \dots, P_{n-1}$, representing the values of the cards from top to bottom.

Output

The output is provided by the interactive library. When testing locally, if the values of $p$ or $q$ go out of bounds, it will output "Out of bound!". If the answer you return is incorrect, it will output "Wrong answer!". Otherwise, it will output "Right Output!" on one line, and the number of times you called the first four functions on the next line.

The interactive library provided to you is different from the final one! However, in the final testing environment, the permutation is still pre-generated and will not change based on your queries!

Examples

Input 1

5
3 4 0 1 2

Output 1

Right Output!
You use 100 operations!

Note 1

This example indicates that you called the first four functions $100$ times and successfully obtained the correct permutation.

Example 2

See the provided files.

Example 3

See the provided files.

Subtasks

For all data, $1 \le n \le 150000$.

Subtask $1$ ($6$ pts): $n \le 1000$

Subtask $2$ ($7$ pts): $n \le 10000$

Subtask $3$ ($38$ pts): $n \le 30000$

Subtask $4$ ($25$ pts): $n \le 50000$

Subtask $5$ ($24$ pts): $n \le 150000$

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.