HDU4819 Mosaic
本文版权归ljh2000和博客园共有,欢迎转载,但须保留此声明,并给出原文链接,谢谢合作。
本文作者:ljh2000
作者博客:http://www.cnblogs.com/ljh2000-jump/
转载请注明出处,侵权必究,保留最终解释权!
Can you help the
God of sheep?
the number of test cases. Then T test cases follow.
Each test case begins
with an integer n (5 < n < 800). Then the following n rows describe the
picture to pixelate, where each row has n integers representing the original
color values. The j-th integer in the i-th row is the color value of cell (i, j)
of the picture. Color values are nonnegative integers and will not exceed
1,000,000,000 (10^9).
After the description of the picture, there is an
integer Q (Q ≤ 100000 (10^5)), indicating the number of mosaics.
Then Q
actions follow: the i-th row gives the i-th replacement made by the God of
sheep: xi, yi, Li (1 ≤ xi, yi ≤ n, 1 ≤ Li < 10000, Li is odd). This means the
God of sheep will change the color value in (xi, yi) (located at row xi and
column yi) according to the Li x Li region as described above. For example, an
query (2, 3, 3) means changing the color value of the cell at the second row and
the third column according to region (1, 2) (1, 3), (1, 4), (2, 2), (2, 3), (2,
4), (3, 2), (3, 3), (3, 4). Notice that if the region is not entirely inside the
picture, only cells that are both in the region and the picture are
considered.
Note that the God of sheep will do the replacement one by one
in the order given in the input.
quotes, t means the index of the test case) at the beginning.
For each
action, print the new color value of the updated cell.
3
1 2 3
4 5 6
7 8 9
5
2 2 1
3 2 3
1 1 3
1 2 3
2 2 3
5
6
3
4
6
//It is made by ljh2000
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <ctime>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <complex>
using namespace std;
typedef long long LL;
const int MAXN = 811;
const int MAXM = 5000011;
int n,m,ju[MAXN][MAXN],X[2],Y[2],cnt,rt,ans,CC;
struct node{ int l,r,ls,rs,maxl,minl,tree; }a[MAXM];
inline int getint(){
int w=0,q=0; char c=getchar(); while((c<'0'||c>'9') && c!='-') c=getchar();
if(c=='-') q=1,c=getchar(); while (c>='0'&&c<='9') w=w*10+c-'0',c=getchar(); return q?-w:w;
} namespace Seg_tree{
inline void build(int &k,int l,int r,int bel){
k=++cnt; a[k].l=l; a[k].r=r; if(l==r) { a[k].minl=a[k].maxl=ju[l][bel]; return ; }
int mid=(l+r)>>1; build(a[k].ls,l,mid,bel); build(a[k].rs,mid+1,r,bel);
a[k].minl=min(a[a[k].ls].minl,a[a[k].rs].minl); a[k].maxl=max(a[a[k].ls].maxl,a[a[k].rs].maxl);
} inline int query_min(int k,int l,int r){
if(Y[0]<=l && r<=Y[1]) return a[k].minl;
int mid=(l+r)>>1;
if(Y[0]>mid) return query_min(a[k].rs,mid+1,r);
else if(Y[1]<=mid) return query_min(a[k].ls,l,mid);
else return min(query_min(a[k].ls,l,mid),query_min(a[k].rs,mid+1,r));
} inline int query_max(int k,int l,int r){
if(Y[0]<=l && r<=Y[1]) return a[k].maxl;
int mid=(l+r)>>1;
if(Y[0]>mid) return query_max(a[k].rs,mid+1,r);
else if(Y[1]<=mid) return query_max(a[k].ls,l,mid);
else return max(query_max(a[k].ls,l,mid),query_max(a[k].rs,mid+1,r));
} inline void modify(int k,int l,int r,int y){
if(l==r) { a[k].minl=a[k].maxl=ans; return ; }
int mid=(l+r)>>1;
if(y<=mid) modify(a[k].ls,l,mid,y); else modify(a[k].rs,mid+1,r,y);
a[k].minl=min(a[a[k].ls].minl,a[a[k].rs].minl); a[k].maxl=max(a[a[k].ls].maxl,a[a[k].rs].maxl);
} inline void update_min(int k,int l,int r,int y){
if(l==r) { a[k].minl=CC; return ; }
int mid=(l+r)>>1;
if(y<=mid) update_min(a[k].ls,l,mid,y); else update_min(a[k].rs,mid+1,r,y);
a[k].minl=min(a[a[k].ls].minl,a[a[k].rs].minl);
} inline void update_max(int k,int l,int r,int y){
if(l==r) { a[k].maxl=CC; return ; }
int mid=(l+r)>>1;
if(y<=mid) update_max(a[k].ls,l,mid,y); else update_max(a[k].rs,mid+1,r,y);
a[k].maxl=max(a[a[k].ls].maxl,a[a[k].rs].maxl);
}
} inline void merge(int &k,node q,node qq){
if(!k) k=++cnt; a[k].maxl=max(q.maxl,qq.maxl); a[k].minl=min(q.minl,qq.minl);
a[k].l=q.l; a[k].r=q.r; if(q.l==q.r) return ;
merge(a[k].ls,a[q.ls],a[qq.ls]);
merge(a[k].rs,a[q.rs],a[qq.rs]);
} inline void build(int &k,int l,int r){
k=++cnt; a[k].l=l; a[k].r=r;
if(l==r) {
Seg_tree::build(a[k].tree,1,n,l);
return;
}
int mid=(l+r)>>1; build(a[k].ls,l,mid); build(a[k].rs,mid+1,r);
merge(a[k].tree,a[ a[a[k].ls].tree ],a[ a[a[k].rs].tree ]);
} inline int query_min(int k,int l,int r){
if(X[0]<=l && r<=X[1]) return Seg_tree::query_min(a[k].tree,1,n);
int mid=(l+r)>>1;
if(X[0]>mid) return query_min(a[k].rs,mid+1,r);
else if(X[1]<=mid) return query_min(a[k].ls,l,mid);
else return min(query_min(a[k].ls,l,mid),query_min(a[k].rs,mid+1,r));
} inline int query_max(int k,int l,int r){
if(X[0]<=l && r<=X[1]) return Seg_tree::query_max(a[k].tree,1,n);
int mid=(l+r)>>1;
if(X[0]>mid) return query_max(a[k].rs,mid+1,r);
else if(X[1]<=mid) return query_max(a[k].ls,l,mid);
else return max(query_max(a[k].ls,l,mid),query_max(a[k].rs,mid+1,r));
} inline void modify(int k,int l,int r,int x,int y){
if(l==r) { Seg_tree::modify(a[k].tree,1,n,y); return ; }
int mid=(l+r)>>1;
if(x<=mid) modify(a[k].ls,l,mid,x,y);
else modify(a[k].rs,mid+1,r,x,y); int lc=a[k].ls,rc=a[k].rs;
int lmin=Seg_tree::query_min(a[lc].tree,a[a[lc].tree].l,a[a[lc].tree].r);
int rmin=Seg_tree::query_min(a[rc].tree,a[a[rc].tree].l,a[a[rc].tree].r);
CC=min(lmin,rmin); Seg_tree::update_min(a[k].tree,a[a[k].tree].l,a[a[k].tree].r,y); int lmax=Seg_tree::query_max(a[lc].tree,a[a[lc].tree].l,a[a[lc].tree].r);
int rmax=Seg_tree::query_max(a[rc].tree,a[a[rc].tree].l,a[a[rc].tree].r);
CC=max(lmax,rmax); Seg_tree::update_max(a[k].tree,a[a[k].tree].l,a[a[k].tree].r,y);
//merge(a[k].tree,a[ a[a[k].ls].tree ],a[ a[a[k].rs].tree ]);
} inline void work(){
int T=getint();
for(int Case=1;Case<=T;Case++) {
printf("Case #%d:\n",Case); n=getint(); for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) ju[i][j]=getint();
for(int i=1;i<=cnt;i++) a[i].tree=a[i].ls=a[i].rs=0; cnt=0; rt=0;
build(rt,1,n); m=getint(); int x,y,z,da,xiao;
while(m--) {
y=getint(); x=getint(); z=getint(); z>>=1;
X[0]=max(x-z,1); X[1]=min(x+z,n);
Y[0]=max(y-z,1); Y[1]=min(y+z,n);
da=query_max(rt,1,n);
xiao=query_min(rt,1,n);
ans=(da+xiao)>>1; printf("%d\n",ans);
Y[0]=Y[1]=y;
modify(rt,1,n,x,y);
}
} } int main()
{
work();
return 0;
}
HDU4819 Mosaic的更多相关文章
- HDU4819 Mosaic【树套树】
LINK 题目大意 给你一个\(n*n\)矩阵,每个点有初始权值 q次询问每次把一个矩形的中心节点变成这个矩形中最大值和最小值的平均数 思路 很显然的树套树啊 就是一开始傻逼了没想到怎么去维护这个东西 ...
- HDU 4819 Mosaic (二维线段树)
Mosaic Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 102400/102400 K (Java/Others)Total S ...
- HDU 4819 Mosaic(13年长春现场 二维线段树)
HDU 4819 Mosaic 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4819 题意:给定一个n*n的矩阵,每次给定一个子矩阵区域(x,y,l) ...
- URAL Mosaic(并查集)(欧拉回路)
Mosaic Time limit: 0.25 secondMemory limit: 64 MB There's no doubt that one of the most important an ...
- Mosaic HDU 4819 二维线段树入门题
Mosaic Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 102400/102400 K (Java/Others)Total S ...
- HDU 4819 Mosaic 二维线段树
Mosaic Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/view.action ...
- 用opencv画矩形打上马赛克Mosaic
/*----------------------------------------------------------------------------- * * 版权声明: * 可以 ...
- Mosaic 前端微服务框架
Mosaic 是一系列的服务.库,集成在一起,定义了组件如何彼此交互,可以用来支持大规模的web 站点开发 一张架构图 说明 尽管上图中的一些组件已经迭代演化了(skipper 的route 配置,上 ...
- 镶嵌数据集 Mosaic Dataset 的常见数据组织方式
镶嵌数据集是ESRI公司推出一种用于管理海量影像数据的数据模型,定义在GeoDatabase数据模型中. 它的常见数据组织方式有两种: 1. 源镶嵌数据集 Source Mosaic Dataset ...
随机推荐
- 《从零开始学Swift》学习笔记(Day 21)——函数返回值
原创文章,欢迎转载.转载请注明:关东升的博客 返回值3种形式:无返回值.单一返回值和多返回值. 无返回值函数 所谓无返回结果,事实上是Void类型,即表示没有数据的类型. 无返回值函数的语法格式有如下 ...
- eval()和exec()函数的区别
(1)eval(str [,globals [,locals ])函数将字符串str当成有效Python表达式来求值,并返回计算结果.(2)exec()函数将字符串str当成有效的Python表达式来 ...
- access 如何导出 cvs 文件?
三部曲 1 access 数据表导出 excel 表格 2 excel 另存为 *.cvs 格式文件 3 数据库导入 *.cvs 文件
- MySQL中的索引提示Index Hint
MySQL数据库支持索引提示(INDEX HINT)显式的高速优化器使用了哪个索引.以下是可能需要用到INDEX HINT的情况 a)MySQL数据库的优化器错误的选择了某个索引,导致SQL运行很慢. ...
- SqlProfiler的替代品-ExpressProfiler
可以用来跟踪执行的sql语句.安装SqlServer之后SqlServerManagementStudio自带一个SqlProfiler,但是如果安装的SqlExpress,那就没有了. 项目的主页在 ...
- Python3.6全栈开发实例[017]
17.念数字:给出一个字典,在字典中标识出每个数字的发音,包括相关符号,然后由用户输入一个数字,让程序读出相对应的发音(不需要语音输出.单纯的打印即可). dics = { '-':'fu', ':' ...
- win7安装composer
安装前请务必确保已经正确安装了 PHP.打开命令行窗口并执行 php -v 查看是否正确输出版本号. 开始安装前需要把open_ssl扩展打开 打开命令行并依次执行下列命令安装最新版本的 Compos ...
- MySQL第二天
回顾 数据库基础知识: 关系型数据库(磁盘)和非关系型数据库(内存) 关系型数据库: 建立在关系模型上的数据库 数据结构: 二维表(比较浪费空间) 操作数据的指令集合: SQL(DDL,DML ...
- servlet3.0 的新特性之二注解代替了web.xml配置文件
servlet3.0 的新特性: 注解代替了 web.xml 文件 支持了对异步的处理 对上传文件的支持 1.注解代替了配置文件 1.删除了web.xml 文件 2. 在Servlet类上添加@Web ...
- boost之内存池
讲到内存池我们会想到对对象进行动态分配的过程new包含三个过程 1.使用operator new分配内存 2.使用placement new 初始化 3.返回内存地址. 分配内存可以分解成分配内存和获 ...