formatting source-code for d7af6fdc8c

This commit is contained in:
github-actions
2020-05-29 23:26:30 +00:00
parent edb3d51ec2
commit 7ad1f171c1
176 changed files with 5342 additions and 4288 deletions

View File

@@ -1,4 +1,4 @@
//Program to calculate length of longest increasing subsequence in an array
// Program to calculate length of longest increasing subsequence in an array
// in O(n log n)
// tested on : https://cses.fi/problemset/task/1145/
@@ -7,30 +7,32 @@
using namespace std;
int LIS(int arr[], int n)
{
set < int > active; // The current built LIS.
set<int> active; // The current built LIS.
active.insert(arr[0]);
// Loop through every element.
for (int i = 1; i < n; ++i)
{
auto get = active.lower_bound(arr[i]);
if (get == active.end())
{
{
active.insert(arr[i]);
} // current element is the greatest so LIS increases by 1.
} // current element is the greatest so LIS increases by 1.
else
{
int val = * get; // we find the position where arr[i] will be in the LIS. If it is in the LIS already we do nothing
{
int val = *get; // we find the position where arr[i] will be in the
// LIS. If it is in the LIS already we do nothing
if (val > arr[i])
{
// else we remove the bigger element and add a smaller element (which is arr[i]) and continue;
{
// else we remove the bigger element and add a smaller element
// (which is arr[i]) and continue;
active.erase(get);
active.insert(arr[i]);
}
}
}
return active.size(); // size of the LIS.
return active.size(); // size of the LIS.
}
int main(int argc, char const * argv[])
int main(int argc, char const* argv[])
{
int n;
cout << "Enter size of array: ";