P1020 [NOIP 1999 提高组] 导弹拦截
点击查看代码
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+10;
int a[N];
int q1[N];
int q2[N];
int main()
{
ios::sync_with_stdio(0),cin.tie(0);
int n=0;
while(cin>>a[n]) n++;
int len1=0,len2=0;
for(int i=0;i<n;i++){
if(len1==0||a[i]<=q1[len1]){
q1[++len1]=a[i];
}else{
int* pos=upper_bound(q1+1,q1+len1+1,a[i],greater<int>());
*pos=a[i];
}
if(len2==0||a[i]>q2[len2]){
q2[++len2]=a[i];
}else{
int* pos=lower_bound(q2+1,q2+len2+1,a[i]);
*pos=a[i];
}
}
cout<<len1<<"\n"<<len2;
return 0;
}

浙公网安备 33010602011771号