-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbitonic_point.cpp
38 lines (30 loc) · 869 Bytes
/
bitonic_point.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
// Author: Jakub Pawlina
// Algorithm: Bitonic Point
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
int bitonic_point(std::vector <int> bitonic_sequence)
{
int position = -1;
for (int i = bitonic_sequence.size() - 1; i >= 1; i /= 2)
{
while (bitonic_sequence[i + position] < bitonic_sequence[i + position + 1])
{
position += i;
}
}
return position + 1;
}
int32_t main()
{
std::ios_base::sync_with_stdio(false);
std::cin.tie(NULL);
std::cout.tie(NULL);
std::vector <int> bitonic_sequence{5, 7, 35, 64, 1024, 1025, 1023, 513, 255, 121, 8, 3, 2, 1};
for (size_t i = 0; i < bitonic_sequence.size(); ++i)
{
std::cout << "[" << i << "] : " << bitonic_sequence[i] << '\n';
}
int position = bitonic_point(bitonic_sequence);
std::cout << "Bitonic Point (" << bitonic_sequence[position] << ") at position " << position << '\n';
return 0;
}