A. Make All Equal
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

If you visit the prehistoric stone circle of Stonehenge at dawn on the longest day of the year, the druids will challenge you to participate in the ancient and sacred pebble game. First, you will be blindfolded, so that you are unable to see anything.

Then, the chief druid will tell you that she has $$$N$$$ piles of stones in a line, where $$$N$$$ is a power of two ($$$N = 2^k$$$ for some integer $$$k$$$).

Piles are indexed from $$$0$$$ to $$$N-1$$$. Each pile has a height $$$H_i$$$, which is a positive integer, and the piles are ordered from smallest to tallest ($$$H_0 \le H_1 \le \ldots \le H_{N-1}$$$). The chief druid tells you the value of $$$N$$$, but not the initial heights.

You can then choose actions of one of the following types:

  1. Select a positive number $$$X$$$ and a subset of the piles $$$S$$$. The druids will then add $$$X$$$ stones to each of the piles in $$$S$$$, and then reorder the piles from smallest to largest.
  2. Choose two piles $$$i$$$ and $$$j$$$. The druids will then tell you whether these two piles currently have the same height.

Your goal is to reach a configuration where all piles have the same height. You take at most $$$Q_\mathrm{add}$$$ actions of the first type, and at most $$$Q_\mathrm{compare}$$$ actions of the second type (see section Scoring).

Implementation Details

You will have to submit a single .cpp source file.

Among this task's attachments you will find a template equal.cpp with a sample implementation.

You have to implement the following function:

void make_all_equal(int N, int Q_add, int Q_compare);
  • Integer $$$N$$$ represents the number of piles.
  • Integer $$$Q_\mathrm{add}$$$ represents the maximum number of times you can call add.
  • Integer $$$Q_\mathrm{compare}$$$ represents the maximum number of times you can call compare.

You can call the following functions:

void add(vector<int> S, long long X);
  • The vector $$$S$$$ must contain distinct integers between $$$0$$$ and $$$N-1$$$ inclusive.
  • Integer $$$X$$$ must be between $$$0$$$ and $$$10^{12}$$$ inclusive.
  • This function will increment $$$H_i$$$ by $$$X$$$ for every $$$i$$$ in $$$S$$$. Then, it will sort the heights in increasing order ($$$H_0 \le \ldots \le H_{N-1}$$$).
  • This function can be called at most $$$Q_\mathrm{add}$$$ times.
bool compare(int i, int j);
  • $$$i$$$ and $$$j$$$ must be between $$$0$$$ and $$$N-1$$$ inclusive.
  • The function will return true if the $$$i$$$-th smallest pile and the $$$j$$$-th smallest pile have the same current height (that is, if $$$H_i = H_j$$$), and false otherwise.
  • This function can be called at most $$$Q_\mathrm{compare}$$$ times.
Input

The task's directory contains a simplified version of the jury grader, which you can use to test your solution locally. The simplified grader reads the input data from stdin, calls the functions that you must implement, and finally writes the output to stdout.

The input is made up of two lines, containing:

  • Line $$$1$$$: the integers $$$N$$$, $$$Q_\mathrm{add}$$$ and $$$Q_\mathrm{compare}$$$, separated by space.
  • Line $$$2$$$: the integers $$$H_i$$$, separated by a space.

Constraints

  • $$$2 \le N \le 2048$$$, and $$$N$$$ is a power of two.
  • The initial heights satisfy $$$1 \le H_0 \le \cdots \le H_{N-1} \le 10^6$$$.
Output

If your program is judged as Accepted, the sample grader prints Accepted: add=U, compare=V where $$$U$$$ and $$$V$$$ are the number of times you called add and compare.

If your program is judged as Wrong Answer, the sample grader prints Wrong Answer: MSG, where MSG is one of:

MessageMeaning
too many calls to addYou called add more than $$$Q_\mathrm{add}$$$ times.
X out of rangeThe integer $$$X$$$ given to add is not between $$$0$$$ and $$$10^{12}$$$ inclusive.
index in S out of rangeAn element of the vector $$$S$$$ given to add is not between $$$0$$$ and $$$N-1$$$ inclusive.
indices in S not distinctThere are two equal elements in the vector $$$S$$$ given to add.
too many calls to compareYou called compare more than $$$Q_\mathrm{compare}$$$ times.
i out of rangeThe integer $$$i$$$ given to compare is not between $$$0$$$ and $$$N-1$$$ inclusive.
j out of rangeThe integer $$$j$$$ given to compare is not between $$$0$$$ and $$$N-1$$$ inclusive.
heights are not equalAfter calling make_all_equal, there are two piles with different heights.
Note
Example interaction.