洛谷 P3437 [POI2006]TET-Tetris 3D 解题报告
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 解题报告的更多相关文章
- 洛谷 P2323 [HNOI2006]公路修建问题 解题报告
P2323 [HNOI2006]公路修建问题 题目描述 输入输出格式 输入格式: 在实际评测时,将只会有m-1行公路 输出格式: 思路: 二分答案 然后把每条能加的大边都加上,然后加小边 但在洛谷的题 ...
- 洛谷P3437 [POI2006]TET-Tetris 3D(二维线段树 标记永久化)
题意 题目链接 Sol 二维线段树空间复杂度是多少啊qwqqq 为啥这题全网空间都是\(n^2\)还有人硬要说是\(nlog^2n\)呀.. 对于这题来说,因为有修改操作,我们需要在外层线段树上也打标 ...
- 洛谷 P3437 [POI2006]TET-Tetris 3D
二维线段树区间更新啊 树套树的外层树,如果是线段树的话一般似乎不能打标记?(毕竟标记不好下传) 然而起码对于这题是可以的...对于外层线段树,每个节点放两个内层线段树dat和setv,分别是得到的值和 ...
- 洛谷 P1852 [国家集训队]跳跳棋 解题报告
P1852 [国家集训队]跳跳棋 题目描述 跳跳棋是在一条数轴上进行的.棋子只能摆在整点上.每个点不能摆超过一个棋子. 我们用跳跳棋来做一个简单的游戏:棋盘上有3颗棋子,分别在\(a\),\(b\), ...
- 洛谷 P3299 [SDOI2013]保护出题人 解题报告
P3299 [SDOI2013]保护出题人 题目描述 出题人铭铭认为给SDOI2012出题太可怕了,因为总要被骂,于是他又给SDOI2013出题了. 参加SDOI2012的小朋友们释放出大量的僵尸,企 ...
- 洛谷 P2059 [JLOI2013]卡牌游戏 解题报告
P2059 [JLOI2013]卡牌游戏 题意 有\(n\)个人玩约瑟夫游戏,有\(m\)张卡,每张卡上有一个正整数,每次庄家有放回的抽一张卡,干掉从庄家起顺时针的第\(k\)个人(计算庄家),干掉的 ...
- 洛谷 P2463 [SDOI2008]Sandy的卡片 解题报告
P2463 [SDOI2008]Sandy的卡片 题意 给\(n(\le 1000)\)串,定义两个串相等为"长度相同,且一个串每个数加某个数与另一个串完全相同",求所有串的最长公 ...
- 洛谷 P2774 方格取数问题 解题报告
P2774 方格取数问题 题目背景 none! 题目描述 在一个有 \(m*n\) 个方格的棋盘中,每个方格中有一个正整数.现要从方格中取数,使任意 2 个数所在方格没有公共边,且取出的数的总和最大. ...
- 洛谷 画栅栏Painting the Fence 解题报告
P2205 画栅栏Painting the Fence 题目描述 \(Farmer\) \(John\) 想出了一个给牛棚旁的长围墙涂色的好方法.(为了简单起见,我们把围墙看做一维的数轴,每一个单位长 ...
随机推荐
- VMware运行时“内部错误”的解决方法
解决方法:打开虚拟机实体目录,如下:发现有两个虚拟机配置文件,一个文件大小为4KB,另一个为空.现在虚拟机默认使用为空的配置文件了. 将大小为空的虚拟机配置文件删除掉,然后将另一个配置文件重名命. 接 ...
- LNMP+HAProxy+Keepalived负载均衡 - LNMP基础环境准备
环境版本说明: 服务器系统:CentOS 7.5: ``` cat /etc/redhat-release CentOS Linux release 7.5.1804 (Core) # 输出结果 `` ...
- 简单的for循环实现九九乘法表
PHP for 循环 语法 for (init counter; test counter; increment counter) { code to be executed; } 参数: init ...
- ios 苹果内购订单验证 --- nodejs实现
实现代码 function IosPlayVerify(data,orderid,cb) { itunesPost(data,function (error,responseData) { if (e ...
- 模块pandas
python之pandas简单介绍及使用(一) https://www.cnblogs.com/misswangxing/p/7903595.html
- PHP.29-TP框架商城应用实例-后台6-商品会员添加-价格、级别
首先把需求分析搞清楚 主要实现两个功能 1.会员管理,设置成为会员的要求 2.添加商品时,可设置会员优惠价格 具体实现 1.建表[会员级别限定表p39_member_level{Id,级别名称,积分下 ...
- 13 Django组件-cookie与session
会话跟踪技术 1 什么是会话跟踪技术 我们需要先了解一下什么是会话!可以把会话理解为客户端与服务器之间的一次会晤,在一次会晤中可能会包含多次请求和响应.例如你给10086打个电话,你就是客户端,而10 ...
- 十四、pymysql模块
一.安装的两种方法 第一种 #安装 pip3 install pymysql 第二种 二.链接,执行sql,关闭(游标) import pymysql user= input('用户名:>> ...
- WCF入门二[WCF的配置文件]
一.概述 往往在很多项目中数据库连接字符串.变量和一些动态的加载类会写在配置文件中.WCF也会在配置文件中写入一些配置参数,比如服务的地址.服务用于发送和接收消息的传输和消息编码等,通过配置文件可以灵 ...
- postman导出excel出现response
https://jingyan.baidu.com/article/915fc414559b4351394b2084.html