[POI2006]Tet-Tetris 3D

Description
Tetris 3D "Tetris" 游戏的作者决定做一个新的游戏, 一个三维的版本, 在里面很多立方体落在平面板,一个立方体开始落下直到碰上一个以前落下的立方体或者落地即停止. 作者想改变一下游戏的目的使得它更大众化,在新游戏中你将知道落下的立方体信息以及位置,你的任务就是回答所有立方体落下后最高的方块的高度.所有的立方体在下落过程中都是垂直的并且不会旋转.平板左下角坐标为原点,并且平行于坐标轴.

Input
第一行给出三个整数 D, S and N ( 1<= N<= 20 000, 1<= D, S <=1 000), 分别表示平板的长和宽以及下落立方体的数目. 接下来N 行每行描述一个立方体. 每行包含5个整数: d, s, w, x and y (1<= d, 0 <=x, d + x<= D, 1 <=s, 0<= y, s + y<= S, 1<= w <=100 000), 分别表示立方体的长\宽\高以及落下的左下角坐标, 长和宽都是平行于平板坐标轴的,落下后立方体着地的四个角坐标分别为: (x, y), (x + d, y), (x, y + s) and (x + d, y + s).

Output
一个整数表示所有立方体落下后最高的方块的高度.

Sample Input
7 5 4
4 3 2 0 0
3 3 1 3 0
7 1 2 0 3
2 3 3 2 2

Sample Output
6


二维线段树,每次取出区间内的最高高度,然后加上新方块的高度,重新加进区间,维护一下最大值就好。空间复杂度\(O(n^2)\)

/*program from Wolfycz*/
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define inf 0x7f7f7f7f
using namespace std;
typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
inline int read(){
    int x=0,f=1;char ch=getchar();
    for (;ch<'0'||ch>'9';ch=getchar())  if (ch=='-')    f=-1;
    for (;ch>='0'&&ch<='9';ch=getchar())    x=(x<<1)+(x<<3)+ch-'0';
    return x*f;
}
inline void print(int x){
    if (x>=10)     print(x/10);
    putchar(x%10+'0');
}
const int N=1e3;
int D,S;
#define ls (p<<1)
#define rs (p<<1|1)
struct Segment{
    int tree[(N<<2)+10],tag[(N<<2)+10];
    void change(int p,int l,int r,int x,int y,int v){
        tree[p]=max(tree[p],v);
        if (x<=l&&r<=y){
            tag[p]=max(tag[p],v);
            return;
        }
        int mid=(l+r)>>1;
        if (x<=mid) change(ls,l,mid,x,y,v);
        if (y>mid)  change(rs,mid+1,r,x,y,v);
    }
    int Query(int p,int l,int r,int x,int y){
        if (x<=l&&r<=y) return tree[p];
        int mid=(l+r)>>1,res=tag[p];
        if (x<=mid) res=max(res,Query(ls,l,mid,x,y));
        if (y>mid)  res=max(res,Query(rs,mid+1,r,x,y));
        return res;
    }
}tree[(N<<2)+10],tag[(N<<2)+10];
void change(int p,int l,int r,int x,int y,int X,int Y,int v){
    tree[p].change(1,1,S,X,Y,v);
    if (x<=l&&r<=y){
        tag[p].change(1,1,S,X,Y,v);
        return;
    }
    int mid=(l+r)>>1;
    if (x<=mid) change(ls,l,mid,x,y,X,Y,v);
    if (y>mid)  change(rs,mid+1,r,x,y,X,Y,v);
}
int Query(int p,int l,int r,int x,int y,int X,int Y){
    if (x<=l&&r<=y) return tree[p].Query(1,1,S,X,Y);
    int mid=(l+r)>>1,res=tag[p].Query(1,1,S,X,Y);
    if (x<=mid) res=max(res,Query(ls,l,mid,x,y,X,Y));
    if (y>mid)  res=max(res,Query(rs,mid+1,r,x,y,X,Y));
    return res;
}
int main(){
    D=read(),S=read();
    for (int n=read();n;n--){
        int d=read(),s=read(),w=read(),x=read(),y=read();
        int ox=x+1,ex=x+d,oy=y+1,ey=y+s;
        int lastans=Query(1,1,D,ox,ex,oy,ey);
        change(1,1,D,ox,ex,oy,ey,lastans+w);
    }
    printf("%d\n",Query(1,1,D,1,D,1,S));
    return 0;
}

转载于:https://www.cnblogs.com/Wolfycz/p/9465545.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值