洛谷 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\) 想出了一个给牛棚旁的长围墙涂色的好方法.(为了简单起见,我们把围墙看做一维的数轴,每一个单位长 ...
随机推荐
- Intellij IDEA 像eclipse那样给maven添加依赖,且Intellij idea里在pom.xml里添加Maven依赖,本地仓库下拉列表显示包很少的血的经验
打开pom.xml,在它里面使用快捷键:ALT+Insert ————>点击dependency 再输入想要添加的依赖关键字,比如:输个spring 出现下图: 根据需求选择版本,完成以后 ...
- Ansible工作架构和原理
特性 模块块化调用持定的模块,完成持定任务 有Paramiko,PyYAML,Jinja2(模板语言)三个关键模块 支持自定义模块 基于Python语法头现 部署简单,基于python和SSH(默认已 ...
- ARM S3C2440 时钟初始化流程
1.设置lock time 2.设置分频系数 3.设置CPU到异步工作模式 4.设置 FCLK 了解 芯片的时钟原理图,以及寄存器的作用 了解芯片的晶振频率,锁相环,分频系数,以及有哪些时钟
- python--Pandas(一)
一.Pandas简介 1.Python Data Analysis Library 或 pandas 是基于NumPy 的一种工具,该工具是为了解决数据分析任务而创建的.Pandas 纳入了大量库和一 ...
- 传输控制协议(TCP)
传输控制协议(TCP)[来自Unix网络编程(卷一)第2章] 1.TCP是一个面向连接.可靠性的传输协议: 2.TCP含有用于动态估算客户与服务器之间往返时间(RTT)的算法,以便它知道等待一个确认需 ...
- 微信小程序推广方案
拥有小程序只是基础,能玩转小程序运营才是关键.本文将会简单讲述十种最实用的小程序推广策略,结合具体案例阐述商家企业如何在拥有小程序后玩转小程序,快速实现小程序的推广. 一. 公众号+小程序 小程序可以 ...
- 4.1 基本类型和引用类型的值【JavaScript高级程序设计第三版】
ECMAScript 变量可能包含两种不同数据类型的值:基本类型值和引用类型值.基本类型值指的是简单的数据段,而引用类型值指那些可能由多个值构成的对象. 在将一个值赋给变量时,解析器必须确定这个值是基 ...
- vue 点击当前元素添加class 去掉兄弟的class
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta http ...
- Hibernate---架构
Hibernate 架构是分层的,作为数据访问层,你不必知道底层 API .Hibernate 利用数据库以及配置数据来为应用程序提供持续性服务(以及持续性对象). 下面是一个非常高水平的 Hiber ...
- CC3200串口UART1配置
1. 首先打开工程\CC3200SDK_1.1.0\example\adc\ewarm,以ADC例程为例,修改串口引脚复用,先看下引脚图 2. 修改引脚复用代码 void PinMuxConfig(v ...