Steven, the monkey, is baking banana bread today!
The recipe for banana bread calls for
Unfortunately, Steven lost the recipe and doesn't remember the ordering!
Fortunately, Steven had sent his recipe to his friend Tony for safekeeping. However, being a monkey, Tony obfuscated the recipe and tells Steven that he can only ask for the number of inversions present in some subarray of array
A pair of indices
Constraints
Array
Interaction
This is an interactive problem.
You will start by reading in a single integer
Note: The grader is NOT adaptive.
After reading
To ask a query, you must output in the form ? l r
to standard output. You will then read a single integer from standard input, which is the number of inversions in the contiguous subarray from
To validate your final answer, you must output !
followed by a space, then
The output must be flushed after every line is printed, including the last line. In C/C++, you can use fflush(stdout)
or cout << endl
, in Java you can use System.out.flush()
, and in Python you can use sys.stdout.flush()
.
At any time, if you ask an invalid query or exceed -1
. Once you read -1
, terminate your program immediately and you will receive a Wrong Answer verdict. Failure to terminate your program may result in an undefined result.
Sample Interaction 1
Note: Do not actually print out <<<
and >>>
. >>>
means that the interactor printed out the line, and <<<
means that you printed out the line.
>>> 5
<<< ? 3 4
>>> 0
<<< ? 1 5
>>> 5
<<< ? 2 4
>>> 0
<<< ! 3 2 4 5 1
Explanation for Sample Interaction 1
Our array is
Sample Interaction 2
>>> 3
<<< ? 1 2
>>> 0
<<< ! 1 2 3
Comments