Question link:
Here
Question:
Similar to hdu4742. The difference is that some of the three tuples are provided directly. Another part is generated using the function he gave. In addition, the value is greater than A> B, which must be ax> BX, ay> by, AZ> BZ.
Ideas:
The idea is similar to hdu4742here. There are just a few tricky issues. Now it is strictly greater. Y is easy to handle. When sorting y, we can sort the numbers in front of them so that we can prevent Y from updating it like it. What I feel is troublesome is what I do like x. This is really not a good idea. Only X and Mid + 1 X are different to each other to create a tree array BV. Then, create a tree array AV regardless of the differences. In this way. If X is equal to Mid + 1, update it with BV. You can use AV to update others.
For details, see the code:
#include<algorithm>#include<iostream>#include<string.h>#include<stdio.h>using namespace std;const int INF=0x3f3f3f3f;const int maxn=300030;typedef long long ll;struct node{ int x,y,z; inline bool operator <(const node& tt) const { if(x!=tt.x) return x<tt.x; if(y!=tt.y) return y<tt.y; return z<tt.z; }} po[maxn];int dp[maxn],sy[maxn],sz[maxn],av[maxn],bv[maxn],ans;int tmp[maxn<<1],ty[maxn],ptr;bool cmp(int a,int b){ if(po[a].y!=po[b].y) return po[a].y<po[b].y; return a>b;}void update(int mv[],int x,int v,int mn){ for(int i=x;i<=mn;i+=i&-i) mv[i]=max(mv[i],v);}int qu(int mv[],int x){ int ret=0; for(int i=x;i>0;i-=i&-i) ret=max(ret,mv[i]); return ret;}void solve(int l,int r){ if(l==r) { ans=max(ans,dp[l]); sz[l]=po[l].z; return; } int mid=(l+r)>>1,le=l,ri=mid+1,len=r-l+1,ml=mid-l+1,lim,h,i; memmove(tmp+ptr,sy+l,len*sizeof(int)); for(i=0;i<len;i++) if(tmp[ptr+i]<=mid)//直接把排好的序划分下去就行了。 sy[le++]=tmp[ptr+i]; else sy[ri++]=tmp[ptr+i]; ptr+=len; solve(l,mid); lim=ptr,ptr-=len; for(i=1;i<=ml;i++) av[i]=bv[i]=0; for(i=ptr;i<lim;i++) { if(tmp[i]<=mid) { h=lower_bound(sz+l,sz+l+ml,po[tmp[i]].z)-(sz+l)+1; update(av,h,dp[tmp[i]],ml); if(po[tmp[i]].x!=po[mid+1].x) update(bv,h,dp[tmp[i]],ml); continue; } h=lower_bound(sz+l,sz+l+ml,po[tmp[i]].z-1)-(sz+l); if(h>=ml||sz[l+h]>po[tmp[i]].z-1) h--; if(h>=0) { int *mv=po[tmp[i]].x==po[mid+1].x?bv:av; dp[tmp[i]]=max(dp[tmp[i]],qu(mv,h+1)+1); } } solve(mid+1,r); merge(sz+l,sz+l+ml,sz+l+ml,sz+l+len,ty); memmove(sz+l,ty,len*sizeof(int));}int A,B,C = ~(1<<31),M = (1<<16)-1;int rd(){ A = 36969 * (A & M) + (A >> 16); B = 18000 * (B & M) + (B >> 16); return (C & ((A << 16) + B)) % 1000000;}int main(){ int m,n,i; while(scanf("%d%d%d%d",&n,&m,&A,&B),m||n||A||B) { for(i=1;i<=n;i++) scanf("%d%d%d",&po[i].x,&po[i].y,&po[i].z); for(i=n+1,n+=m;i<=n;i++) po[i].x=rd(),po[i].y=rd(),po[i].z=rd(); ptr=ans=0; sort(po+1,po+n+1); for(i=1;i<=n;i++) sy[i]=i,dp[i]=1; sort(sy+1,sy+n+1,cmp); solve(1,n); printf("%d\n",ans); } return 0;}
Uvalive 6667 longest chain (divide and conquer the triple Lis & tree array)