https://www.acmicpc.net/problem/2352

lower_bound(LIS + 1, LIS + Size + 1, arr[i]) - LIS;

1번쨰 파라미터: first 범위

2번쨰 파라미터: last 범위

3번쨰 파라미터: value

//참조: http://dyngina.tistory.com/16  



#include<iostream>

using namespace std;

#include<algorithm>

int arr[40001];

int LIS[40001];

int n,ans=0,Size=1;

int main()

{

cin.tie(0);

ios::sync_with_stdio(false);

cin >> n;

for (int i = 1; i <= n; i++)

{

cin >> arr[i];

}

LIS[1] = arr[1];

int tmp;

for(int i=2;i<=n;i++)

{

if (LIS[Size] < arr[i])

{

Size++;

LIS[Size] = arr[i];

continue;

}

tmp = lower_bound(LIS + 1, LIS + Size + 1, arr[i]) - LIS;

LIS[tmp] = arr[i];

}

ans = Size;

cout << ans << "\n";

return 0;

}

+ Recent posts