题目链接:http://www.lydsy.com:808/JudgeOnline/problem.php?id=1513

题意:三维空间,有一些立方体在垂直下落。立方体的左下角坐标(x,y)以及长宽高d,s,w。A落在B上时将停止下落(即使A只有一小块跟B重合就算A会落在B上)。求最后最大的高度。

思路:每次覆盖时找到区域最大值,加上当前立方体的高度。

int xL,xR,yL,yR;
int h;

int n,m;

struct Seg
{
    int f[N<<1],s[N<<1];

    void insert(int t,int L,int R,int ll,int rr,int h)
    {
        f[t]=max(f[t],h);
        if(L==ll&&R==rr)
        {
            s[t]=max(s[t],h);
            return;
        }
        int M=(L+R)>>1;
        if(rr<=M) insert(t<<1,L,M,ll,rr,h);
        else if(ll>M) insert(t<<1|1,M+1,R,ll,rr,h);
        else
        {
            insert(t<<1,L,M,ll,M,h);
            insert(t<<1|1,M+1,R,M+1,rr,h);
        }
    }

    int query(int t,int L,int R,int ll,int rr)
    {
        if(L==ll&&R==rr) return f[t];

        int ans=s[t];
        int M=(L+R)>>1;
        if(rr<=M) upMax(ans,query(t<<1,L,M,ll,rr));
        else if(ll>M) upMax(ans,query(t<<1|1,M+1,R,ll,rr));
        else
        {
            upMax(ans,query(t<<1,L,M,ll,M));
            upMax(ans,query(t<<1|1,M+1,R,M+1,rr));
        }
        return ans;
    }
};

struct Seg1
{
    Seg f[N<<1],s[N<<1];

    void insert(int t,int L,int R,int ll,int rr)
    {
        f[t].insert(1,1,m,yL,yR,h);
        if(L==ll&&R==rr)
        {
            s[t].insert(1,1,m,yL,yR,h);
            return;
        }
        int M=(L+R)>>1;
        if(rr<=M) insert(t<<1,L,M,ll,rr);
        else if(ll>M) insert(t<<1|1,M+1,R,ll,rr);
        else
        {
            insert(t<<1,L,M,ll,M);
            insert(t<<1|1,M+1,R,M+1,rr);
        }
    }

    int query(int t,int L,int R,int ll,int rr)
    {
        if(L==ll&&R==rr) return f[t].query(1,1,m,yL,yR);
        int ans=s[t].query(1,1,m,yL,yR);
        int M=(L+R)>>1;
        if(rr<=M) upMax(ans,query(t<<1,L,M,ll,rr));
        else if(ll>M) upMax(ans,query(t<<1|1,M+1,R,ll,rr));
        else
        {
            upMax(ans,query(t<<1,L,M,ll,M));
            upMax(ans,query(t<<1|1,M+1,R,M+1,rr));
        }
        return ans;
    }
};

Seg1 a;

int Q;

int main()
{
    RD(n,m,Q);
    while(Q--)
    {
        int d,s,w,x,y;
        scanf("%d%d%d%d%d",&d,&s,&w,&x,&y);
        xL=x+1;
        xR=x+d;
        yL=y+1;
        yR=y+s;
        h=a.query(1,1,n,xL,xR);
        h+=w;
        a.insert(1,1,n,xL,xR);
    }
    xL=yL=1;
    xR=n;
    yR=m;
    int ans=a.query(1,1,n,1,n);
    printf("%d\n",ans);
}

BZOJ 1513 [POI2006]Tet-Tetris 3D的更多相关文章

  1. bzoj 1513 [POI2006]Tet-Tetris 3D(二维线段树)

    1513: [POI2006]Tet-Tetris 3D Time Limit: 30 Sec  Memory Limit: 162 MBSubmit: 540  Solved: 175[Submit ...

  2. bzoj 1513 POI2006 Tet-Tetris 3D 二维线段树+标记永久化

    1511: [POI2006]OKR-Periods of Words Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 351  Solved: 220[S ...

  3. bzoj1513【POI2006】Tet-Tetris 3D

    1513: [POI2006]Tet-Tetris 3D Time Limit: 30 Sec  Memory Limit: 162 MB Submit: 733  Solved: 245 [Subm ...

  4. 模拟 - BZOJ 1510 [POI2006] Kra-The Disks

    BZOJ 1510 [POI2006] Kra-The Disks 描述 Johnny 在生日时收到了一件特殊的礼物,这件礼物由一个奇形怪状的管子和一些盘子组成. 这个管子是由许多不同直径的圆筒(直径 ...

  5. 【BZOJ】1513: [POI2006]Tet-Tetris 3D

    题意 给\(n(1 \le n \le 20000)\)个立方体\((x, y, z)\),依次落下.求所有立方体落下完了以后最高的高度. 分析 平面求最大值,平面更新最大值. 题解 二维线段树走起, ...

  6. bzoj 1510 [POI2006]Kra-The Disks 二分

    1510: [POI2006]Kra-The Disks Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 466  Solved: 272[Submit][ ...

  7. bzoj 1520 [POI2006]Szk-Schools 费用流

    [POI2006]Szk-Schools Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 743  Solved: 381[Submit][Status][ ...

  8. bzoj 1517 [POI2006]Met 贪心

    [POI2006]Met Time Limit: 15 Sec  Memory Limit: 162 MBSubmit: 203  Solved: 108[Submit][Status][Discus ...

  9. BZOJ 1511: [POI2006]OKR-Periods of Words

    Description 求一个最长周期. Sol KMP. 一个点的最短周期就是 \(i-next[i]\) 此外 \(i-next[next[i]],i-next[next[next[i]]]\) ...

随机推荐

  1. 使用java访问 动态链接库(dll)

    在这个时候,我们可以使用的java技术有jni.jna.jnative,这个大部分都可以完成任务.但是有时候我们在实际情况中拿到的dll有变化,当我们需要用的函数是在dll中的类里面的话,我们再使用前 ...

  2. 怎么学习C++?

    一个学习十年c++的建议如下: 其实学习C++的读书顺序应该是这样的(对于有C基础的朋友): C++ Primer Effective C++ Exceptional C++ Inside the C ...

  3. 【bs4】安装beautifulsoup

    Debian/Ubuntu,install $ apt-get install python-bs4 easy_install/pip $ easy_install beautifulsoup4 $ ...

  4. 有趣的insert死锁

    昨天看到一个很有意思的死锁,拿来记录下: 环境:deadlock on 事务隔离级别: read commited 表结构: root::>show create table lingluo\G ...

  5. linux设备驱动归纳总结(三):2.字符型设备的操作open、close、read、write【转】

    本文转载自:http://blog.chinaunix.net/uid-25014876-id-59417.html linux设备驱动归纳总结(三):2.字符型设备的操作open.close.rea ...

  6. Linux, Mac下Shell 数组 Array 的修理工

    我的测试基本都是在Mac,及Unix环境下测试的,如无特别注明,默认就是Mac 不论你看到这篇随笔是被shell array的奇淫巧技,还是发现shell array就在一对{}里面就可以做那么多勾当 ...

  7. 那些情况该使用它们spin_lock到spin_lock_irqsave【转】

    转自:http://blog.csdn.net/wesleyluo/article/details/8807919 权声明:本文为博主原创文章,未经博主允许不得转载. Spinlock的目的是用来同步 ...

  8. Verilog HDL基础语法讲解之模块代码基本结构

    Verilog HDL基础语法讲解之模块代码基本结构   本章主要讲解Verilog基础语法的内容,文章以一个最简单的例子"二选一多路器"来引入一个最简单的Verilog设计文件的 ...

  9. Hibernate,JPA注解@EmbeddedId

    定义组合主键的几种语法: 将组件类注解为@Embeddable,并将组件的属性注解为@Id 将组件的属性注解为@EmbeddedId 将类注解为@IdClass,并将该实体中所有属于主键的属性都注解为 ...

  10. Mysql数据库知识-Mysql索引总结 mysql mysql数据库 mysql函数

    mysql数据库知识-Mysql索引总结: 索引(Index)是帮助MySQL高效获取数据的数据结构. 下边是自己整理的资料与自己的学习总结,,做一个汇总. 一.真的有必要使用索引吗? 不是每一个性能 ...