其他分享
首页 > 其他分享> > 洛谷:P1020 导弹拦

洛谷:P1020 导弹拦

作者:互联网

#include<iostream>
#include<string>
#include<algorithm>
#define DEBUG if(  1  )
#define N 100010
using namespace std;
int z[N],z1[N],z2[N],n;
int main(){
    while(cin>>z[n++]);n--;
    int l1=1,pp,l2=1;
    z1[0]=z[0];
    z2[0]=z[0];
    for(int i=1;i<n;i++){
        if(z1[l1-1] >= z[i]){
            z1[l1++] = z[i];
        }else{
            pp=upper_bound(z1,z1+l1,z[i],greater<int>()) - z1;
            z1[pp]=z[i];
        }
        if(z2[l2-1] < z[i]){
            z2[l2++] = z[i];
        }else{
            pp=lower_bound(z2,z2+l2,z[i]) - z2;
            z2[pp]=z[i];
        }

    }
    cout<<l1<<endl<<l2;
    return 0;
}

https://www.luogu.com.cn/problem/P1020

标签:pp,洛谷,int,导弹,P1020,l2,include,z1,z2
来源: https://www.cnblogs.com/forwhat00/p/13267950.html