#P94. Interactive Problem Test 3: A Tough Binary Search
Interactive Problem Test 3: A Tough Binary Search
Person in charge
Problem Description
We have a binary search implementation (whose code you cannot see as it's implemented in the judge). Your task is to write an adaptive interaction library that ensures the actual number of searches performed is never less than the theoretical minimum required to guarantee successful search.
Interaction Protocol
This is an interactive problem.
Use the following template:
#include <bits/stdc++.h>
using namespace std;
int respond(int n, int q, int x, vector<pair<int, int>> p)
{
int z = 0;
// ...
return z;
}
Parameters:
- : Upper bound for current binary search. The target is a positive integer .
- : Number of searches already performed in this round (excluding current search).
- : Current pivot value. Return based on 's relation to :
- if
- if
- if
- You may dynamically modify as long as it doesn't contradict previous search information.
- : Array of length (1-indexed) containing previous search info in this round:
- Each pair represents:
- : value passed by judge
- : value returned by your program
- Guaranteed to be in chronological order.
- Each pair represents:
Constraints:
- Function will be called at most times
- Total search rounds does not exceed
Sample
Three search rounds are shown below (AC solution):
Call | Return | Explanation |
---|---|---|
respond(4, 0, 1, []); |
Round starts. Your program sets | |
respond(4, 1, 2, [(1, 0)]); |
Your program changes to | |
respond(4, 2, 4, [(1, 0), (2, 0)]); |
remains | |
respond(4, 3, 3, [(1, 0), (2, 0), (4, 2)]); |
Round ends ( searches) | |
respond(1, 0, 1, []); |
Round ends immediately ( search) | |
respond(5, 0, 3, []); |
Round starts. Your program sets | |
respond(5, 1, 2, [(3, 2)]); |
Your program changes to | |
respond(5, 2, 1, [(3, 2), (2, 2)]); |
Round ends ( searches) |