Bi-increasing vector P99753


Statement
 

pdf   zip   main.cc

In this problem, we say that a vector with nn integer numbers v[0..n1]v[0..n-1] is bi-increasing if n2n \ge 2, v[0]>v[n1]v[0] > v[n-1], and there exists an index jj between 00 and n2n-2 such that:

  • v[0]v[j1]v[j]v[0] \le \ldots \le v[j-1] \le v[j],

  • v[j+1]v[j+2]v[n1]v[j+1] \le v[j+2] \le \ldots \le v[n-1].

For instance, the vector [12,12,15,20,1,3,3,5,9][12, 12, 15, 20, 1, 3, 3, 5, 9] is bi-increasing (with j=3j = 3).

Implement an efficient function

    bool search(int x, const vector<int>& v);

such that, given an integer number xx and a bi-increasing vector vv, returns if xx is in vv or not. You can use and implement auxiliary functions if you need them.

Precondition

The vector vv is bi-increasing.

Observation

You only need to submit the required procedure; your main program will be ignored.

Information
Author
Salvador Roura
Language
English
Translator
Salvador Roura
Original language
Catalan
Other languages
Catalan
Official solutions
C++
User solutions
C++