样例敢不敢再坑一点??
居然样例把解法给透露了!
求LIS和LDS
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cmath>
#include <vector>
#include <deque>
#include <algorithm>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#define REP(i,n) for(int i=0;i<(n);i++)
#define REP1(i,n) for(int i=1;i<=(n);i++)
#define FOR(i,a,b) for (int i=(a);i<=(b);i++)
#define CLR(x,n) memset(x,n,sizeof(x))
#define PN printf("\n")
#define read(x) scanf("%d",&x)
#define read2(x,y) scanf("%d%d",&x,&y)
#define read3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define write(x) printf("%d",x)
#define write1(x) printf("%d ",x)
#define writeln(x) printf("%d\n",x)
#define write2(x,y) printf("%d %d",x,y)
#define writeln2(x,y) printf("%d %d\n",x,y)
#define write3(x,y,z) printf("%d %d %d",x,y,z)
#define writeln3(x,y,z) printf("%d %d %d\n",x,y,z)
#define INF 1<<30
using namespace std;
void renew(int &x,int y){
if (x<y)x=y;}
int a[30010],ans1,ans2,d[30010],g[30010];
int cmp1(int a,int b){return a<=b;}
int cmp2(int a,int b){return a>=b;}
int main()
{
int n;read(n);ans1=ans2=0;
REP1(i,n)read(a[i]);
REP1(i,n)g[i]=INF;
REP1(i,n){
//REP1(j,n)write1(g[j]);PN;
int k=lower_bound(g+1,g+n+1,a[i],cmp1)-g;
d[i]=k;renew(ans1,d[i]);
g[k]=a[i];
}//writeln(ans1);REP1(i,n)write1(d[i]);PN;
REP1(i,n)g[i]=-INF;
REP1(i,n){
//REP1(j,n)write1(g[j]);PN;
int k=lower_bound(g+1,g+n+1,a[i],cmp2)-g;
d[i]=k;renew(ans2,d[i]);
g[k]=a[i];
}//writeln(ans2);REP1(i,n)write1(d[i]);
writeln(n-max(ans1,ans2));
system("pause");
return 0;
}