xiaojie4620

导航

洛谷 P1020 [NOIP1999 普及组] 导弹拦截

Coidng

#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>

using namespace std;
const int N = 1e5 + 10;
int q[N];
int f[N], g[N];
int len = 0;
int main()
{
    int n = 0;
    while (cin >> q[n])
        n++;
    //    n++;
    for (int i = 0; i < n; i++)
    {
        //cout << q[i] << endl;
        int l = 0, r = len;
        while (l < r)
        {
            int mid = l + r + 1 >> 1;
            if (f[mid] >= q[i]) l = mid;
            else r = mid - 1;
        }
        len = max(len, r + 1);
        f[r + 1] = q[i];
    }
    cout << len << endl;

    int cnt = 0;
    for (int i = 0; i < n; i++)
    {
        int k = 0;
        while (k < cnt && g[k] < q[i]) k++;
        g[k] = q[i];
        if (k >= cnt) cnt++;
    }
    cout << cnt << endl;
    return 0;
}

 

posted on 2022-03-20 10:59  kuokuo  阅读(38)  评论(0编辑  收藏  举报