Time limit: 0.3s
Memory limit: 256MB
Input:
Output:
Task
Marius has a secret permutation . 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)
(, ) — Returns the minimum value between and .
Your task is to find the positions of the numbers and in Marius' permutation.
If and , then both and are considered correct answers.
Implementation
You need to implement the function:
std::pair<int, int> find_positions(int n);
Where:
- is the size of the permutation.
- Your function should return a pair of integers representing the positions (1-indexed) of the values and , 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 .
- You may call this function up to times per test case.
- If you exceed the allowed number of queries, your program will receive a
Wrong Answer
.
Constraints and Clarifications
- The permutation is a permutation of integers from to .
- 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 and the other holds is considered correct.
- You must
#include "rapid.h"
Example
Suppose the hidden permutation is [3, 1, 5, 2, 4]
, so .
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:
- (which is )
- (which is )
Then, you return:
return {3, 5}; // or {5, 3}
Scoring
Let be the number of compare
calls used in a test case. Then your score for that test case will be:
1
if- if
0
if
Subtasks
# | Score | Restrictions |
---|---|---|
1 | 4 | , , |
2 | 8 | , , |
3 | 16 | , , |
4 | 20 | , , |
5 | 12 | , , |
6 | 24 | , , |
7 | 16 | , , |
Notes
- After each call to
compare(i, j)
, the return value is immediately available. - The total number of test cases is .
- 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.