luogu#P8168. [eJOI 2021] BinSearch
[eJOI 2021] BinSearch
Problem Description
bool binary_search(int n, int p[], int target){
int left = 1, right = n;
while(left < right){
int mid = (left + right) / 2;
if(p[mid] == target)
return true;
else if(p[mid] < target)
left = mid + 1;
else
right = mid - 1;
}
if(p[left] == target) return true;
else return false;
}
As everyone knows, when the function above is given a monotone non-decreasing array and appears in the array , it will return . However, if is not monotone, this is no longer guaranteed.
You are given a positive integer and an array . The testdata guarantees that there exists a positive integer such that .
Define as the number of indices for which the return value of is not equal to . Your task is to find a permutation of such that is as small as possible (see the scoring rules for details).
Input Format
This problem contains multiple test cases.
The first line contains a positive integer , the number of test cases.
For each test case, the first line contains a positive integer . The second line contains a string of length (only characters 0 and 1, with no spaces). If the -th character is 1, then ; otherwise .
Output Format
Output lines. For each line, output the permutation you found. This problem uses Special Judge, and the output format is very strict: there must be no extra characters such as trailing spaces at the end of each line.
4
3
111
7
1111111
3
000
7
0000000
1 2 3
1 2 3 4 5 6 7
3 2 1
7 6 5 4 3 2 1
2
3
010
7
0010110
3 2 1
7 3 1 5 2 4 6
Hint
Scoring Rules
- If for a subtask, all permutations satisfy , then you get of that subtask's total score.
- Otherwise, if for a subtask, all permutations satisfy , then you get of that subtask's total score.
Due to Luogu's scoring mechanism, the actual score for each test point is the floor of the value above. For example, if a subtask's total score is and all permutations in that subtask satisfy , then the score is rather than .
Sample 1 Explanation
In the first two test cases, .
In the third test case, , because $\texttt{binary\_search(n, p, 2)}=\texttt{true} \neq b_2$.
In the fourth test case, , because $\texttt{binary\_search(n, p, 4)}=\texttt{true} \neq b_4$.
Sample 2 Explanation
In both test cases, .
Constraints and Notes
This problem uses bundled tests.
- Subtask 1 (3 pts): .
- Subtask 2 (4 pts): .
- Subtask 3 (16 pts): .
- Subtask 4 (25 pts): .
- Subtask 5 (22 pts): and the testdata is random.
- Subtask 6 (30 pts): No special restrictions.
For of the testdata, , , .
Notes
This problem is translated from eJOI2021 Day 2 A BinSearch. You are welcome to hack the self-written Special Judge via private message or by making a post.
Translated by ChatGPT 5