标签:
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)
#include<iostream> #include<cstdio> #include<cmath> #include<string> #include<queue> #include<algorithm> #include<stack> #include<cstring> #include<vector> #include<list> #include<set> #include<map> using namespace std; #define ll __int64 #define mod 1000000007 #define inf 999999999 //#pragma comment(linker, "/STACK:102400000,102400000") int scan() { int res = 0 , ch ; while( !( ( ch = getchar() ) >= ‘0‘ && ch <= ‘9‘ ) ) { if( ch == EOF ) return 1 << 30 ; } res = ch - ‘0‘ ; while( ( ch = getchar() ) >= ‘0‘ && ch <= ‘9‘ ) res = res * 10 + ( ch - ‘0‘ ) ; return res ; } struct is { int l,r; int num; }tree[100010*3]; int a[100010]; int gg[100010]; void buildtree(int l,int r,int pos) { tree[pos].l=l; tree[pos].r=r; if(l==r) { tree[pos].num=inf; return; } int mid=(l+r)>>1; buildtree(l,mid,pos*2); buildtree(mid+1,r,pos*2+1); tree[pos].num=min(tree[pos*2].num,tree[pos*2+1].num); } void update(int point,int pos,int change) { if(tree[pos].l==tree[pos].r&&tree[pos].l==point) { tree[pos].num=change; return; } int mid=(tree[pos].l+tree[pos].r)>>1; if(point<=mid) update(point,pos*2,change); else update(point,pos*2+1,change); tree[pos].num=min(tree[pos*2].num,tree[pos*2+1].num); } int query(int l,int r,int pos) { if(tree[pos].l==l&&tree[pos].r==r) return tree[pos].num; int mid=(tree[pos].l+tree[pos].r)>>1; if(r<=mid) return query(l,r,pos*2); else if(l>mid) return query(l,r,pos*2+1); else return min(query(l,mid,pos*2),query(mid+1,r,pos*2+1)); } int main() { int x,y,z,i,t; while(~scanf("%d%d",&x,&y)) { for(i=1;i<=x;i++) gg[i]=1; buildtree(1,x,1); for(i=1;i<=x;i++) scanf("%d",&a[i]); for(i=y+2;i<=x;i++) { if(query(gg[i-y-1],gg[i-y-1],1)>a[i-y-1]) update(gg[i-y-1],1,a[i-y-1]); int st=1; int en=x,mid; if(tree[1].num>=a[i]) gg[i]=1; else { while(st<en) { mid=(st+en)>>1; if(query(mid+1,en,1)<a[i]) st=mid+1; else en=mid; } gg[i]=st+1; } } int ans=0; for(i=1;i<=x;i++) ans=max(ans,gg[i]); printf("%d\n",ans); } return 0; }
标签:
原文地址:http://www.cnblogs.com/jhz033/p/5463861.html