HDU 4742 Pinball Game 3D (three-dimensional LIS&CDQ Division & Bit maintenance maximum)

Source: Internet
Author: User

Pinball Game 3DTime limit:10000/5000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 688 Accepted Submission (s): 276


Problem DESCRIPTIONRD is a smart boy and an excel in pinball game. However, playing common 2D Pinball game for a great number of times results in accumulating tedium.

Recently, RD has found a new type of pinball game, a 3D pinball game. The 3D Pinball game space can be regarded as a three dimensional coordinate system containing N balls. A ball can is considered as a point. At the beginning, RD made a shot and hits a ball. The ball hits by RD'll move and May hits another ball and the ' another ball ' may move and hit another another ball, etc. B UT once a ball hits another ball, it'll disappear.

RD is skilled in this kind of the game, so he was able to control every ball ' s moving direction. But there was a limitation:if ball A's coordinate is (X1,Y1,Z1) and ball B's coordinate is (X2,Y2,Z2), then a can hits B on ly if X1 <= x2 and y1 <= y2 and Z1 <= Z2.

Now, your should help RD to calculate the maximum number of balls that can is hit and the number of different shooting Sche Mes that can achieve. Schemes is different if the sets of hit balls is not the same. The order doesn ' t matter.
Inputthe first line contains one integer T indicating the number of cases.
In each case, the first line contains one integer N indicating the number of balls.
The next N lines each contains three non-negative integer (x, Y, z) and indicating the coordinate of a ball.
The data satisfies T <= 3, N <=, 0 <= x, y, z <=, no, and Balls has the same coordinate in one case.
Outputprint-integers for each case in a line, indicating the maximum number of balls that can is hit and the number of Different shooting schemes. As the number of schemes can quite large, you should output this number mod 230.
Sample Input
232 0 00 1 00 1 153 0 00 1 00 0 10 2 23 3 3

Sample Output
2 2Hintin the first case, RD can shoot the second ball at first and hit the third ball indirectly.  In the second case, RD can shoot the second or the third ball initially and hits the fourth ball as well as the fifth ball. Schemes is both the best.

Source2013 ACM/ICPC Asia Regional Hangzhou Online
recommendliuyiding | We have carefully selected several similar problems for you:5061 5059 5058 5053

pid=5052 "target=" _blank ">5052 test Instructions: just give you n (1e5) triples, and then ask you to ask this n triples of Lis. And so the number of programs for LIS. A three-ancestor-A is more ax>=bx,ay>=by,az>=bz than another ancestor B. idea: if it is a one-dimensional is very good to do. The order is finished. Two-dimensional words. Sorts the X. Then Dp[i] represents the longest sequence length with the I end. Dp[i]=max (dp[i],dp[j]+1). J<i&&y[j]<y[i]. Three-dimensional words will be used to divide the idea of treatment. Let's first sort x by x and press Y. Y and press X in the same row. This will ensure that dp[i] must have been transferred by 1~i-1. And then we'll be able to divide the rule.

For example, we want to calculate the DP value of [L,R]. Mid= (L+R)/2 If we have calculated the DP value of [L,MID]. We are not able to update [MID+1,R] 's DP value with [L,MID] DP value.

Since Dp[i] must have been transferred by 1~i-1, we were able to build a tree-like array to maintain the maximum DP with Z-values of ZZ (since this question was queried [1,x] throughout the entire interval, it was possible to use a tree-like array to maintain the highest value). Of course the Z-value is the value after discretization. Then we sort on both sides of the Y. Then for each DP [MID+1,R] We press the Y value from small to large to update. Insert the Y value of [l,mid] into the tree array first.

Then query the array array of z less than its own maximum DP. This ensures that the elements x, y in the tree array are reasonable and the z of the query is reasonable. Then the recursion is done. First solve (L,MID) and then Update [mid+1,r] again solve (mid+1,r).

Of course, recursion can also be done by way of some sort operations (merge sort) to improve efficiency. See the code for details:

#include <algorithm> #include <iostream> #include <string.h> #include <stdio.h>using namespace std;const int inf=0x3f3f3f3f;const int Maxn=100010;const int mod=1<<30;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],mv[maxn],ans;int tmp[maxn<<1],ty[maxn],ptr;ll NUM[MAXN],NV[MAXN], Ansn;bool cmp (int a,int b)//Note Y must be in this line. Otherwise, y may appear equal to the case when the i+1 is in front of I.    {if (PO[A].Y!=PO[B].Y) return po[a].y<po[b].y; return a<b;} void update (int x,int v,ll d,int mn) {for (int i=x;i<=mn;i+=i&-i) {if (V>mv[i]) mv[i]=v,n        V[i]=d;    else if (v==mv[i]) Nv[i]+=d;    }}int qu (int x,ll &nn) {int ret=0;        for (int i=x;i>0;i-=i&-i) {if (Ret<mv[i]) ret=mv[i],nn=nv[i]; ElsE if (Mv[i]==ret) nn+=nv[i]; } return ret;}        void Solve (int l,int r) {if (l==r) {if (Dp[l]>ans) ans=dp[l],ansn=num[l];        else if (Dp[l]==ans) ansn+=num[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)//directly to the orderly division of the line down can be.

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++) mv[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 (H,DP[TMP[I]],NUM[TMP[I]],ML); Continue } h=lower_bound (Sz+l,sz+l+ml,po[tmp[i]].z)-(SZ+L); if (h>=ml| | SZ[L+H]&GT;PO[TMP[I]].Z) h--; if (h>=0) {ll cc=0; int Tt=qu (H+1,CC) +1; if (Tt>dp[tmp[i]]) dp[tmp[i]]=tt,num[tmp[i]]=cc; else if (tt==dp[tmp[i]]&&tt!=1) num[tmp[i]]+=cc; }} 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 main () {int t,n,i; scanf ("%d", &t); while (t--) {scanf ("%d", &n); for (i=1;i<=n;i++) scanf ("%d%d%d",&PO[I].X,&AMP;PO[I].Y,&AMP;PO[I].Z); ansn=ptr=ans=0; Sort (po+1,po+n+1); for (i=1;i<=n;i++) sy[i]=i,dp[i]=1,num[i]=1; Sort (sy+1,sy+n+1,cmp); Solve (1,n); printf ("%d%i64d\n", ans,ansn%mod); } return 0;} /* Send a set of data. Many of the online code is not over this group. It was because of the sort y that i+1 to the I front. resulting in less updates very much Hangzhou electric data compared to water over water.

1172 0 02 1 11 2 11 0 00 0 10 2 00 2 20 1 12 0 11 2 20 1 02 0 22 2 20 1 21 0 21 1 10 0 2*/



HDU 4742 Pinball Game 3D (three-dimensional LIS&AMP;CDQ Division &amp; Bit maintenance maximum)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.