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. BZOJ1491: [NOI2007]社交网络(Floyd 最短路计数)

    Time Limit: 10 Sec  Memory Limit: 64 MBSubmit: 2343  Solved: 1266[Submit][Status][Discuss] Descripti ...

  2. 【ODT】cf896C - Willem, Chtholly and Seniorious

    仿佛没用过std::set Seniorious has n pieces of talisman. Willem puts them in a line, the i-th of which is ...

  3. lintcode_397_最长上升连续子序列

    最长上升连续子序列   描述 笔记 数据 评测 给定一个整数数组(下标从 0 到 n-1, n 表示整个数组的规模),请找出该数组中的最长上升连续子序列.(最长上升连续子序列可以定义为从右到左或从左到 ...

  4. 如果理解&&运算符和各类数值的布尔值

    &&(且运算符):表示二者都为true才为true: 短路原则:例如 : a && b;   当a为true时,程序无论如何都会走b,而不管b为true或者false ...

  5. 40.VUE学习之--组件之间的数据传参父组件向子组件里传参,props的使用实例操作

    父组件向子组件里传参,props的使用实例 <!DOCTYPE html> <html> <head> <meta charset="utf-8&q ...

  6. php 文件操作和文件上传

    文件操作 http://www.w3school.com.cn/php/php_file.asp http://www.w3school.com.cn/php/php_file_open.asp ht ...

  7. python3 练习题100例 (二十)

    #!/usr/bin/env python3# -*- coding: utf-8 -*-"""练习二十:判断一个年份是否是闰年公历闰年计算方法:1.普通年能被4整除且不 ...

  8. Python学习笔记:logging(日志处理)

    在一个软件中,日志是可以说必不可少的一个组成部分,通常会在定位客户问题或者记录软件使用情况等场景中会用到.logging模板块是Python的一个内置标准库,用于实现对日志的控制输出,对于平常的日志输 ...

  9. Codeforces Round #449 (Div. 2) C. DFS

    C. Nephren gives a riddle time limit per test 2 seconds memory limit per test 256 megabytes input st ...

  10. 大话目标检测经典模型(RCNN、Fast RCNN、Faster RCNN)

      目标检测是深度学习的一个重要应用,就是在图片中要将里面的物体识别出来,并标出物体的位置,一般需要经过两个步骤:1.分类,识别物体是什么 2.定位,找出物体在哪里 除了对单个物体进行检测,还要能支持 ...