Rapid

Time limit: 0.3s Memory limit: 256MB Input: Output:

Task

Marius has a secret permutation p1,p2,,pnp_1, p_2, \ldots, p_n. Although Marius does not want to reveal the values of the elements in the permutation, he is willing to answer a limited number of queries of the following type:

  • compare(i, j) (1i,jn1 \le i, j \le n, iji \ne j) — Returns the minimum value between pip_i and pjp_j.

Your task is to find the positions of the numbers n1n - 1 and nn in Marius' permutation.

If pi=n1p_i = n - 1 and pj=np_j = n, then both (i,j)(i, j) and (j,i)(j, i) are considered correct answers.

Implementation

You need to implement the function:

std::pair<int, int> find_positions(int n);

Where:

  • nn is the size of the permutation.
  • Your function should return a pair of integers representing the positions (1-indexed) of the values nn and n1n-1, in any order.

To interact with Marius' permutation, you can use the following function provided by the grader:

int compare(int i, int j);

This function returns min(pi,pj)\min(p_i, p_j).

  • You may call this function up to limlim times per test case.
  • If you exceed the allowed number of queries, your program will receive a Wrong Answer.

Constraints and Clarifications

  • The permutation pp is a permutation of integers from 11 to nn.
  • The permutation is fixed for the duration of a test case.
  • The number of queries used affects the score (see Scoring below).
  • All indices are 1-based.
  • Any valid pair of indices where one holds nn and the other holds n1n - 1 is considered correct.
  • You must #include "rapid.h"

Example

Suppose the hidden permutation is [3, 1, 5, 2, 4], so n=5n = 5.

Then your function might call:

compare(1, 2); // returns 1
compare(1, 3); // returns 3
compare(3, 5); // returns 4

From these, you can deduce:

  • p3=5p_3 = 5 (which is nn)
  • p5=4p_5 = 4 (which is n1n - 1)

Then, you return:

return {3, 5}; // or {5, 3}

Scoring

Let qq be the number of compare calls used in a test case. Then your score for that test case will be:

  • 1 if q10000q \le 10\,000
  • lim+1qlim+110000\frac{\text{lim} + 1 - q}{\text{lim} + 1 - 10\,000} if 10000<qlim10\,000 < q \le \text{lim}
  • 0 if q>limq > \text{lim}

Subtasks

# Score Restrictions
1 4 t=25t = 25, 2n1402 \le n \le 140, lim=12000\text{lim} = 12\,000
2 8 t=25t = 25, n=3000n = 3\,000, lim=12000\text{lim} = 12\,000
3 16 t=25t = 25, n=5000n = 5\,000, lim=12000\text{lim} = 12\,000
4 20 t=25t = 25, n=7500n = 7\,500, lim=12000\text{lim} = 12\,000
5 12 t=25t = 25, n=9300n = 9\,300, lim=11000\text{lim} = 11\,000
6 24 t=25t = 25, n=9600n = 9\,600, lim=10200\text{lim} = 10\,200
7 16 t=25t = 25, n=9900n = 9\,900, lim=10000\text{lim} = 10\,000

Notes

  • After each call to compare(i, j), the return value is immediately available.
  • The total number of test cases is t=25t = 25.
  • You may assume that the grader resets the hidden permutation for each test case.
  • If your solution fails any test case, your submission will be considered incorrect.

Log in or sign up to be able to send submissions!