bzoj1513 "POI2006" Tet-tetris 3D

Source: Internet
Author: User

1513: [Poi2006]tet-tetris 3D time limit: $ Sec Memory Limit: 162 MB
Submit: 733 Solved: 245
[Submit] [Status] [Discuss] Descriptiontask:tetris 3D "Tetris" the author of the game decided to make a new game, a three-dimensional version, in which a lot of cubes fell on the flat plate, and a cube began to fall until it hit a previously falling cube or landed and stopped. The author wants to change the purpose of the game to make it more popular, in the new game you will know the drop of the cube information and location, your task is to answer all the cubes fall after the highest block height. All cubes are vertical and do not rotate during the fall. The bottom left corner coordinates are the origin and are parallel to the axis The first line of the.  input gives three integers D, S and N (1<= n<=, 1<= D, S <=1 000), respectively, representing the length and width of the plate and the number of drop cubes. The next n rows describe a cube for each row. Each line consists of 5 integers: D, S, W, X and Y (1<= D, 0 <=x, D + x<= D, 1 <=s, 0<= y, S + y<= s, 1<= W <=100 000), respectively Represents the length \ width \ height of the cube and the lower left corner coordinates of the drop, both long and wide are parallel to the flat axis, and the four angular coordinates of the cube's ground are: (x, Y), (x + D, y), (x, y + s) and (x + D, y + s).  output an entire The number represents the height of the highest block after all the cubes fall. Sample Input7 5 4
4 3 2) 0 0
3 3 1) 3 0
7 1 2) 0 3
2 3 3) 2 2
Sample Output6
HINT

Source



Topic: Given a two-dimensional matrix, each time you ask for a rectangular range max, and update all the numbers in the rectangle to max+p.

It is easy to think of the two-dimensional line segment tree , but there are two problems: the two-dimensional line tree of the tag and the information upload is not easy to achieve.

How to solve it? The answer is to use tags to perpetuate them.

We use V and tag to represent the maximum value that the child node has calculated and the maximum value that completely overrides the interval. Each change to the path of all the V and the bottom of the tag are modified, each query will be on the path of all the V and the bottom of the tag to take the maximum value.




#include <set> #include <map> #include <ctime> #include <queue> #include <cmath> #include <cstdio> #include <vector> #include <cstring> #include <cstdlib> #include <iostream># Include<algorithm> #define LL Long long#define inf 1000000000using namespace Std;ll read () {ll X=0,f=1;char ch=get    char (); while (ch< ' 0 ' | |    Ch> ' 9 ') {if (ch== '-') F=-1;ch=getchar ();}    while (ch>= ' 0 ' &&ch<= ' 9 ') {x=x*10+ch-' 0 '; Ch=getchar ();} return x*f;}    int d,s,n;int ql,qr,qd,qu;struct segx{int v[3005],tag[3005];        void change (int k,int l,int r,int x,int y,int val) {V[k]=max (v[k],val);        if (l==x&&y==r) {Tag[k]=max (tag[k],val); return;}        int mid= (L+R) >>1;        if (x<=mid) Change (K<<1,l,mid,x,min (Mid,y), Val);    if (y>mid) Change (K<<1|1,mid+1,r,max (x,mid+1), y,val);        } int query (int k,int l,int r,int x,int y) {if (l==x&&y==r) return v[k]; int mid= (L+R) >>1,ans=tag[k];       if (x<=mid) Ans=max (Ans,query (K<<1,l,mid,x,min (mid,y)));        if (y>mid) Ans=max (Ans,query (K<<1|1,mid+1,r,max (x,mid+1), y));    return ans;    }};struct segy{segx v[3005],tag[3005];        void change (int k,int l,int r,int x,int y,int val) {v[k].change (1,1,s,qd,qu,val);        if (l==x&&y==r) {tag[k].change (1,1,s,qd,qu,val); return;}        int mid= (L+R) >>1;        if (x<=mid) Change (K<<1,l,mid,x,min (Mid,y), Val);    if (y>mid) Change (K<<1|1,mid+1,r,max (x,mid+1), y,val);        } int query (int k,int l,int r,int x,int y) {if (l==x&&r==y) return v[k].query (1,1,s,qd,qu);        int mid= (L+R) >>1,ans=tag[k].query (1,1,s,qd,qu);        if (x<=mid) Ans=max (Ans,query (K<<1,l,mid,x,min (mid,y)));        if (y>mid) Ans=max (Ans,query (K<<1|1,mid+1,r,max (x,mid+1), y));    return ans; }}t;int Main () {d=read (); S=read ();    N=read ();    int d,s,w,x,y; for (int i=1;i<=n;i++) {d=read (); S=read ();W=read (); X=read (); Y=read ();        Ql=x+1;qr=x+d;qd=y+1;qu=y+s;        int Ans=t.query (1,1,D,QL,QR);    T.change (1,1,D,QL,QR,ANS+W);    } qd=1;qu=s;    printf ("%d\n", T.query (1,1,d,1,d)); return 0;}


bzoj1513 "POI2006" Tet-tetris 3D

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.