-
Notifications
You must be signed in to change notification settings - Fork 0
/
findinsortrotate.cpp
68 lines (62 loc) · 1.63 KB
/
findinsortrotate.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include <bits/stdc++.h>
// Aarif Khan
// Codechef: https://www.codechef.com/users/aarifkhan_7
// Github: https://github.com/aarifkhan7
#define pi (3.141592653589)
#define MOD 1e9+7
#define ll long long int
#define all(x) x.begin(), x.end()
#define range(a, b) for(int i = a; i < b; i++)
#define range1(a, b) for(int j = a; j < b; j++)
#define inint(x) int x; cin >> x;
#define inarr(x, n) int arr[n]; range(0, n){cin >> x[i];}
#define inll(x) ll x; cin >> x;
#define instr(x) string x; cin >> x;
#define printc(cont) for(auto x : cont) cout << x << ' '; cout << '\n';
#define printp(cont) for(auto x : cont) cout << x.first << ' ' << x.second << '\n';
#define fast ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
#define pii pair<int,int>
#define vi vector<int>
#define pb push_back
#define mp make_pair
using namespace std;
bool bs(int arr[], int low, int high, int t){
if(high < low)
return false;
int mid = (low + high) / 2;
if(arr[mid] == t){
return true;
}else{
if(arr[mid] < t){
return bs(arr, mid + 1, high, t);
}else{
return bs(arr, 0, mid - 1, t);
}
}
}
void solve(){
inint(n);
inarr(arr, n);
inint(target);
int pivot = 0;
range(0,n){
if(arr[i] > arr[pivot]){
pivot = i;
}
}
pivot++;
if(bs(arr, 0, pivot-1, target) || bs(arr, pivot, n-1, target)){
cout << "true\n";
}else{
cout << "false\n";
}
}
int main()
{
fast;
int t; cin >> t;
while(t--){
solve();
}
return 0;
}