P3437 [POI2006]TET-Tetris 3D

题目描述

The authors of the game "Tetris" have decided to make a new, three-dimensional version, in which cuboids would fall down on a rectangular platform. The blocks fall down separately in a certain order, just like in the two-dimensional game. A block falls down until it reaches an obstacle: the platform or another block, that has already stopped - then it stops and remains in this exact position till the game is over.

However, the authors wanted to change the spirit of the game, turning it from a simple arcade-game into a play far more puzzling. Knowing the order of the falling blocks and their flight path the player's task is to tell the height of the highest point of the arrangement after all blocks have fallen down (and stopped). All the blocks are falling down vertically and do not rotate while falling. For convenience we'll introduce a cartesian coordinate system on the platform, with the center in one of the platform's corners and the axes parallel to the platform's edges.

Write a programme that automates verification of the player's answer.

TaskWrite a programme that:

reads the descriptions of subsequent falling blocks from the standard input,determines the height of the highest point of the arrangement of blocks after all have fallen down and stopped,writes the result to the standard output.

给定一个矩阵,初始每个位置上的元素都是0,每次选择一个子矩形,将这个子矩形内的值修改为这个子矩形内的最大值+h,求最终所有位置上的最大值

输入输出格式

输入格式:

In the first line of the input there are three integers DD, SS and NN (1\le N\le 20\ 0001≤N≤20 000, 1\le D,S\le 1\ 0001≤D,S≤1 000), separated by single spaces and denoting respectively: the length and the depth of the platform and the number of blocks that are going to fall down on it. In the following NN lines the descriptions of subsequent blocks are given, one in each line.

Each description of a block consists of five integers: dd,ss,ww,xx and yy (1\le d1≤d, 0\le x0≤x, d+x\le Dd+x≤D, 1\le s1≤s, 0\le y0≤y, s+y\le Ss+y≤S, 1\le w\le 100\ 0001≤w≤100 000), representing a block of length dd depth ss and height ww. This very block will be be falling down on the platform with its d\times sd×s face as the bottom, where the length and depth of the block are parallel to those of the platform. The coordinates of the vertices of the projection of the block on the platform are: (x,y)(x,y), (x+d,y)(x+d,y), (x,y+s)(x,y+s) and (x+d,y+s)(x+d,y+s).

第一行输入D,S,N,就是长宽和操作数

后面每行读入5个数,d,s,h,x,y,表示把

(x,y),(x+d-1,y),(x,y+s-1),(x+d-1,y+s-1)为四顶点的子矩阵进行操作

h就是题目描述里的h

注意行列是从0开始数的

输出格式:

The first and only line of the standard output should contain exactly one integer, the height of the highest point of the arrangement of blocks after all have fallen down and stopped.


注意到这个矩形修改矩形查询最大值的所有位置上的值是非减的,否则我们没法使用二维线段树配合标记永久化完成。


先考虑一维的情况,区间求最大值,区间赋值最大值加上某个正数

在线段树中维护一个\(mx\)和一个\(tag\),分别表示区间最大值和修改后的值

对于修改操作,对路径上的每一个节点都用待修改的值尝试更新\(mx\)数组,因为这个节点一定包含这个小区间,所以可以更新

但\(tag\)操作只有区间完全被覆盖时才更新,不下传一直呆在这个区间

对于查询操作,对路径上的每一个节点都尝试使用\(tag\)数组更新答案,因为tag是对整个区间打的,所以子区间可以直接使用

在区间完全被覆盖的情况下,我们才可以用\(mx\)数组更新答案

这就是所谓的标记永久化

为什么要这样,因为第二维的树是没法使用子节点快速更新答案的,也不好下传


再考虑第二维的情况,第二维的线段树每一个节点都放着两颗颗第一维线段树

一颗代表\(mx\)树,一颗代表\(tag\)树

然后剩下的就和第一维的情况非常相似了


Code:

#include <cstdio>
const int N=2050;
int n,m;
int max(int x,int y){return x>y?x:y;}
#define ls id<<1
#define rs id<<1|1
struct segy
{
int mx[N],tag[N];
void change(int id,int l,int r,int L,int R,int val)
{
mx[id]=max(mx[id],val);
if(l==L&&r==R)
{
tag[id]=max(tag[id],val);
return;
}
int Mid=L+R>>1;
if(r<=Mid) change(ls,l,r,L,Mid,val);
else if(l>Mid) change(rs,l,r,Mid+1,R,val);
else change(ls,l,Mid,L,Mid,val),change(rs,Mid+1,r,Mid+1,R,val);
}
int query(int id,int l,int r,int L,int R)
{
if(l==L&&r==R)
return mx[id];
int ans=tag[id],Mid=L+R>>1;
if(r<=Mid) ans=max(ans,query(ls,l,r,L,Mid));
else if(l>Mid) ans=max(ans,query(rs,l,r,Mid+1,R));
else ans=max(ans,max(query(ls,l,Mid,L,Mid),query(rs,Mid+1,r,Mid+1,R)));
return ans;
}
};
struct segx
{
segy mx[N],tag[N];
void change(int id,int l,int r,int L,int R,int ll,int rr,int val)
{
mx[id].change(1,ll,rr,1,m,val);
if(l==L&&r==R)
{
tag[id].change(1,ll,rr,1,m,val);
return;
}
int Mid=L+R>>1;
if(r<=Mid) change(ls,l,r,L,Mid,ll,rr,val);
else if(l>Mid) change(rs,l,r,Mid+1,R,ll,rr,val);
else change(ls,l,Mid,L,Mid,ll,rr,val),change(rs,Mid+1,r,Mid+1,R,ll,rr,val);
}
int query(int id,int l,int r,int L,int R,int ll,int rr)
{
if(l==L&&r==R)
return mx[id].query(1,ll,rr,1,m);
int ans=tag[id].query(1,ll,rr,1,m),Mid=L+R>>1;
if(r<=Mid) ans=max(ans,query(ls,l,r,L,Mid,ll,rr));
else if(l>Mid) ans=max(ans,query(rs,l,r,Mid+1,R,ll,rr));
else ans=max(ans,max(query(ls,l,Mid,L,Mid,ll,rr),query(rs,Mid+1,r,Mid+1,R,ll,rr)));
return ans;
}
}t;
int main()
{
int d,s,h,x,y,k;
scanf("%d%d%d",&n,&m,&k);
while(k--)
{
scanf("%d%d%d%d%d",&d,&s,&h,&x,&y),++x,++y;
t.change(1,x,x+d-1,1,n,y,y+s-1,t.query(1,x,x+d-1,1,n,y,y+s-1)+h);
}
printf("%d\n",t.query(1,1,n,1,n,1,m));
return 0;
}

2018.9.4

洛谷 P3437 [POI2006]TET-Tetris 3D 解题报告的更多相关文章

  1. 洛谷 P2323 [HNOI2006]公路修建问题 解题报告

    P2323 [HNOI2006]公路修建问题 题目描述 输入输出格式 输入格式: 在实际评测时,将只会有m-1行公路 输出格式: 思路: 二分答案 然后把每条能加的大边都加上,然后加小边 但在洛谷的题 ...

  2. 洛谷P3437 [POI2006]TET-Tetris 3D(二维线段树 标记永久化)

    题意 题目链接 Sol 二维线段树空间复杂度是多少啊qwqqq 为啥这题全网空间都是\(n^2\)还有人硬要说是\(nlog^2n\)呀.. 对于这题来说,因为有修改操作,我们需要在外层线段树上也打标 ...

  3. 洛谷 P3437 [POI2006]TET-Tetris 3D

    二维线段树区间更新啊 树套树的外层树,如果是线段树的话一般似乎不能打标记?(毕竟标记不好下传) 然而起码对于这题是可以的...对于外层线段树,每个节点放两个内层线段树dat和setv,分别是得到的值和 ...

  4. 洛谷 P1852 [国家集训队]跳跳棋 解题报告

    P1852 [国家集训队]跳跳棋 题目描述 跳跳棋是在一条数轴上进行的.棋子只能摆在整点上.每个点不能摆超过一个棋子. 我们用跳跳棋来做一个简单的游戏:棋盘上有3颗棋子,分别在\(a\),\(b\), ...

  5. 洛谷 P3299 [SDOI2013]保护出题人 解题报告

    P3299 [SDOI2013]保护出题人 题目描述 出题人铭铭认为给SDOI2012出题太可怕了,因为总要被骂,于是他又给SDOI2013出题了. 参加SDOI2012的小朋友们释放出大量的僵尸,企 ...

  6. 洛谷 P2059 [JLOI2013]卡牌游戏 解题报告

    P2059 [JLOI2013]卡牌游戏 题意 有\(n\)个人玩约瑟夫游戏,有\(m\)张卡,每张卡上有一个正整数,每次庄家有放回的抽一张卡,干掉从庄家起顺时针的第\(k\)个人(计算庄家),干掉的 ...

  7. 洛谷 P2463 [SDOI2008]Sandy的卡片 解题报告

    P2463 [SDOI2008]Sandy的卡片 题意 给\(n(\le 1000)\)串,定义两个串相等为"长度相同,且一个串每个数加某个数与另一个串完全相同",求所有串的最长公 ...

  8. 洛谷 P2774 方格取数问题 解题报告

    P2774 方格取数问题 题目背景 none! 题目描述 在一个有 \(m*n\) 个方格的棋盘中,每个方格中有一个正整数.现要从方格中取数,使任意 2 个数所在方格没有公共边,且取出的数的总和最大. ...

  9. 洛谷 画栅栏Painting the Fence 解题报告

    P2205 画栅栏Painting the Fence 题目描述 \(Farmer\) \(John\) 想出了一个给牛棚旁的长围墙涂色的好方法.(为了简单起见,我们把围墙看做一维的数轴,每一个单位长 ...

随机推荐

  1. Scott Young-《如何高效学习》

    1.如果你只用一种方式了解某样事物,那么你就没有真正了解它.事情真正含义的秘密取决于我们如何将其与我们所了解的其他事情相联系.很好联系的内容可使你将想法融于脑中,从各种角度看问题,直至你找到合适自己的 ...

  2. Python线程间事件通知

    Python事件机制 事件机制:这是线程间最简单的通信机制:一个线程发送事件,其他线程等待事件事件机制使用一个内部的标志,使用set方法进行使能为True,使用clear清除为falsewait方法将 ...

  3. OB如何创建租户

    一.        先导知识: 资源隔离是保证用户间相互不受影响的重要手段.数据库的资源隔离主要有以下方式: l  服务器隔离 l  数据库隔离:sqlserver.oceanbase.oracle ...

  4. yum 仓库配置

    [base]name=aliyum basebaseurl=https://mirrors.aliyun.com/centos/6/os/x86_64/                        ...

  5. git 常用命令及仓库创建

    一.常用命令 1.添加到本地仓库缓存 git add . 2.查看本地仓库状态 git status 3.提交到本地仓库 git commit -am 'project init' 4.连接线上分支 ...

  6. Delphi中DLL的创建和使用(转)

    Delphi中DLL的创建和使用     1.DLL简介:   2.调用DLL:   3.创建DLL:   4.两个技巧:   5.初始化:   6.例外处理.            1.DLL简介  ...

  7. L2-032 彩虹瓶 (25 分)

    L2-032 彩虹瓶 (25 分)   彩虹瓶的制作过程(并不)是这样的:先把一大批空瓶铺放在装填场地上,然后按照一定的顺序将每种颜色的小球均匀撒到这批瓶子里. 假设彩虹瓶里要按顺序装 N 种颜色的小 ...

  8. mysql学习第三天笔记

    连接连接是在多个表之间通过一定的连接条件,使表之间发生关联,进而能从多个表之间获取数据.在 WHERE子句中书写连接条件. 如果在多个表中出现相同的列名,则需要使用表名作为来自该表的列名的前缀. N个 ...

  9. ansible-3

    setup ansible_all_ipv4_addresses # ipv4的所有地址 ansible_all_ipv6_addresses # ipv6的所有地址 ansible_date_tim ...

  10. [Django]我的第一个网页,报错啦~(自己实现过程中遇到问题以及解决办法)

    环境配置: python :2.7.13 django:1.10.5 OS:Win7(64位)& Centos7 问题描述  解决办法   global name 'render' is no ...