其他分享
首页 > 其他分享> > P1020 导弹拦截

P1020 导弹拦截

作者:互联网

严格上升的话,减1就好啦

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<queue>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<sstream>
#pragma GCC optimize(2)
#define inf 2147483647
#define N 1000010
#define For(i,a,b) for(int i=a;i<=b;++i)
#define p(a) putchar(a)
#define g() getchar()

using namespace std;
int n,ans,m;
int f[N],t[N],b[N];
int a[N];
string s;
char c[100];
void in(int &x){
    int y=1;char c=getchar();x=0;
    while(c<'0'||c>'9'){if(c=='-')y=-1;c=getchar();}
    while(c<='9'&&c>='0'){ x=(x<<1)+(x<<3)+c-'0';c=getchar();}
    x*=y;
}
void o(int x){
    if(x<0){putchar('-');x=-x;}
    if(x>9)o(x/10);
    putchar(x%10+'0');
}

int getmax(int k){
    int Max=0;
    for(;k>0;k-=(-k)&k)
        Max=max(Max,t[k]);
    return Max;
}

void modify(int k,int Max){
    for(;k<=500000;k+=(-k)&k)
        t[k]=max(t[k],Max);
}

int main(){
    getline(cin,s);
    istringstream ss(s);
    while(ss>>c){
        int len=(int)strlen(c);
        n++;
        For(i,0,len-1)
            a[n]=(a[n]<<1)+(a[n]<<3)+c[i]-'0';
    }
      For(i,1,n)
          b[i]=a[n-i+1];
      For(i,1,n){
          f[i]=getmax(b[i])+1;
          ans=max(ans,f[i]);
          modify(b[i],f[i]);
      }
      o(ans);p('\n');
      ans=0;
      memset(t,0,sizeof(t));
      memset(f,0,sizeof(f));
      For(i,1,n){
          f[i]=getmax(a[i]-1)+1;
          ans=max(ans,f[i]);
          modify(a[i],f[i]);
      }
      o(ans);
    return 0;
}

 

标签:10,int,Max,len,导弹,P1020,拦截,include,define
来源: https://www.cnblogs.com/war1111/p/11268198.html