Test instructions: N spheres in three-dimensional space, corresponding coordinates (x, y, z). Outputs the length of the LIS and the number of scenarios.
First you can sort by x, first reduce one dimension, then the left Y, Z, on y cdq divide, press Y size with the previous update behind. The z-direction discretization is then maintained with a tree-like array.
1#include <Set>2#include <map>3#include <cmath>4#include <ctime>5#include <queue>6#include <stack>7#include <cstdio>8#include <string>9#include <vector>Ten#include <cstdlib> One#include <cstring> A#include <iostream> -#include <algorithm> - using namespacestd; thetypedef unsignedLong Longull; -typedefLong Longll; - Const intINF =0x3f3f3f3f; - Const DoubleEPS = 1e-8; + Const intMAXN = 1e5+Ten; - Const intMoD =1<< -; + struct Ball A { at 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]; in structDP - { to intlen,cnt; + DP () {} -DP (int_len,int_cnt): the Len (_len), CNT (_cnt) {} * } DP[MAXN],C[MAXN]; $ intVec[maxn],idx;Panax NotoginsengInlineintLowbit (intx) - { the returnX &-x; + } AInlinevoidUpdate (DP &DP1, DP &DP2) the { + if(Dp1.len <Dp2.len) -DP1 =DP2; $ Else if(Dp1.len = =Dp2.len) $Dp1.cnt + =dp2.cnt; - } -InlinevoidModifyintX,DP &d) the { - while(x <=idx)Wuyi { the Update (C[X],D); -X + =lowbit (x); Wu } - } AboutDP Query (intx) $ { -DP ans = DP (0,0); - while(x) - { A Update (ans,c[x]); +X-=lowbit (x); the } - returnans; $ } theInlinevoidCLR (intx) the { the while(x <=idx) the { -C[X] = DP (0,0); inX + =lowbit (x); the } the } About voidCDQ (intLintR) the { the if(L = =R) the return ; + intMid = (L + r) >>1; - CDQ (L, mid); the for(inti = l; I <= R; i++)Bayi { theTmpball[i] =Ball[i]; thetmpball[i].x =0; - } -Sort (tmpball+l,tmpball+r+1); the for(inti = l; I <= R; i++) the { the if(Tmpball[i].idx <=mid) the { - Modify (Tmpball[i].z,dp[tmpball[i].idx]); the } the Else the {94DP tmp =query (tmpball[i].z); thetmp.len++; the Update (DP[TMPBALL[I].IDX],TMP); the }98 } About for(inti = l; I <= R; i++) - {101 if(Tmpball[i].idx <=mid)102 {103 CLR (tmpball[i].z);104 } the }106CDQ (mid+1, R);107 }108 intMainvoid)109 { the #ifndef Online_judge111Freopen ("In.txt","R", stdin); the #endif113 intT, N; thescanf ("%d",&T); the while(t--) the {117scanf ("%d",&n);118 for(inti =1; I <= N; i++)119 { -scanf ("%d%d%d", &ball[i].x, &BALL[I].Y, &ball[i].z);121vec[i-1] =ball[i].z;122 }123Sort (ball+1, ball+n+1);124Sort (vec,vec+n); theIDX = unique (vec,vec+n)-Vec;126 for(inti =1; I <= N; i++)127 { -Ball[i].z = Lower_bound (vec,vec+idx,ball[i].z)-VEC +1;129Ball[i].idx =i; theDp[i] = DP (1,1);131 } theCDQ (1, n);133DP ans = DP (0,0);134 for(inti =1; I <= N; i++)135 {136 Update (ans,dp[i]);137 }138printf"%d%d\n", Ans.len, ans.cnt%MoD);139 } $ return 0;141}
HDU4742----Pinball Game 3D (three-dimensional LIS, CDQ Division)