Channel
Test instructions: give you n (1e5) triples, and then ask you to ask this n triples of Lis. And so the number of programs for LIS. One ancestor A is larger than the other, and the condition is AX>=BX,AY>=BY,AZ>=BZ
Idea: first by x sort, first reduce one dimension, then left Y, Z, on y cdq divide, press the size of Y with the previous update behind. The z-direction discretization is then maintained with a tree-like array to
Code:
#include <cstdio>#include<cstring>#include<algorithm>using namespaceStd;typedefLong Longll;Const intINF =0x3f3f3f3f;Const intMAXN = 1e5+Ten;Const intMoD =1<< -;structball{intX,y,z,idx; BOOL operator< (ConstBall &RHS)Const{ returnX < Rhs.x | | (x = = rhs.x && y < rhs.y) | | (x = = Rhs.x && y = = Rhs.y && Z <rhs.z); }} BALL[MAXN],TMPBALL[MAXN];structdp{intlen,cnt; DP () {} DP (int_len,int_cnt): Len (_len), CNT (_cnt) {}} DP[MAXN],C[MAXN];intVec[maxn],idx;intCOLOR[MAXN], C;inlineintLowbit (intx) { returnX &-x;} InlinevoidUpdate (DP &DP1, DP &DP2) { if(Dp1.len <Dp2.len) DP1=DP2; Else if(Dp1.len = =Dp2.len) dp1.cnt+=dp2.cnt;} InlinevoidModifyintX,DP &d) { while(x <=idx) { if(color[x]! = C) color[x] = c,c[x] = DP (0,0); Update (C[X],D); X+=lowbit (x); }}DP Query (intx) {DP ans= DP (0,0); while(x) {if(Color[x] = =C) Update (ans,c[x]); X-=lowbit (x); } returnans;} InlinevoidCLR (intx) { while(x <=idx) {C[x]= DP (0,0); X+=lowbit (x); }}BOOLcmp (ball A, ball b) {if(A.y! = b.y)returnA.y <b.y; returnA.idx <B.idx;}voidCDQ (intLintR) { if(L = =R)return ; intMid = (L + r) >>1; CDQ (L, mid); for(inti = l; I <= R; i++) {Tmpball[i]=Ball[i]; tmpball[i].x=0; } sort (Tmpball+l,tmpball+r+1, CMP); ++b; for(inti = l; I <= R; i++){ if(Tmpball[i].idx <=mid) {Modify (Tmpball[i].z,dp[tmpball[i].idx]); } Else{DP tmp=query (TMPBALL[I].Z); Tmp.len++; Update (DP[TMPBALL[I].IDX],TMP); }} CDQ (Mid+1, R);}intMain () {intT, N; scanf ("%d",&T); while(t--) {scanf ("%d",&N); for(inti =1; I <= N; i++) {scanf ("%d%d%d", &ball[i].x, &BALL[I].Y, &ball[i].z); Vec[i-1] =ball[i].z; } sort ( ball+1, ball+n+1); Sort (Vec,vec+N); IDX= Unique (vec,vec+n)-VEC; for(inti =1; I <= N; i++) {ball[i].z= Lower_bound (vec,vec+idx,ball[i].z)-VEC +1; Ball[i].idx=i; Dp[i]= DP (1,1); } CDQ (1, N); DP ans= DP (0,0); for(inti =1; I <= N; i++) Update (ans,dp[i]); printf ("%d%d\n", Ans.len, ans.cnt%MoD); } return 0;}
View Code
"CDQ" HDU 4742 Pinball Game 3D