http://mirror.codeforces.com/contest/439/problem/D
Ternary search can only be used on strictly increasing or decreasing sequence.
But, I think the problem is special in the sense that the search space is strictly decreasing first then some equal values and then strictly increasing.
Thus, ternary search can be used here. But I need to prove that if two f(p) == f(p + 1), then the value must be the answer.