#BS0000106. Tìm kiếm nhị phân trên dãy chưa sắp xếp (Out of Sorts)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Tìm kiếm nhị phân trên dãy chưa sắp xếp (Out of Sorts)
Out of Sorts
Source: Kattis
Version: Phuoc Hung OJ Extended
Problem Statement
Generate distinct values from using seed , which is not part of the array. Ann forgot to sort the generated array and still performs ordinary binary search with the lower midpoint and left/right choices by comparison. Count how many of its own values can be found by this search on the UNSORTED array.
Input
A single line contains in that order.
Output
Print the count of generated values that remain findable by standard binary search on the unsorted array.
Subtasks
- Subtask 1 (20 points): ; ; ; all generated are pairwise distinct.
- Subtask 2 (30 points): ; ; ; all generated are pairwise distinct.
- Subtask 3 (50 points): ; ; ; all generated are pairwise distinct.
Examples
Input
5 8 1 3 3
Output
2
Explanation
Using the recurrence yields . Search for succeeds immediately at middle index . Search for compares against , goes right, then finds at index . Search for goes right on and then left on , incorrectly missing its actual index ; similarly and are missed. Thus exactly two values are findable.