hdu 4819 Mosaic 树套树 模板
Can you help the God of sheep?
InputThe first line contains an integer T (T ≤ 5) indicating 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.��OutputFor each test case, print a line "Case #t:"(without quotes, t means the index of the test case) at the beginning.
For each action, print the new color value of the updated cell.Sample Input
1
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
Sample Output
Case #1:
5
6
3
4
6 题意:

看清楚是单点修改。 题解,树套树,外面一层是那几行,里面是行的列区间,nlognlogn的时间复杂度。
#include<cstring>
#include<cmath>
#include<algorithm>
#include<iostream>
#include<cstdio> #define N 807
#define ll long long
using namespace std;
inline int read()
{
int x=,f=;char ch=getchar();
while(ch>''||ch<''){if (ch=='-') f=-;ch=getchar();}
while(ch<=''&&ch>=''){x=(x<<)+(x<<)+ch-'';ch=getchar();}
return x*f;
} int n,m;
int a[N][N];
struct Node
{
int mi,mx;
}tr[N<<][N<<]; void build_sec(int lct,int p,int l,int r,int fla)
{
if (l==r)
{
if (fla)tr[lct][p].mi=tr[lct][p].mx=a[fla][l];
else tr[lct][p].mi=min(tr[lct<<][p].mi,tr[lct<<|][p].mi),tr[lct][p].mx=max(tr[lct<<][p].mx,tr[lct<<|][p].mx);
return;
}
int mid=(l+r)>>;
build_sec(lct,p<<,l,mid,fla),build_sec(lct,p<<|,mid+,r,fla);
if (fla)
{
tr[lct][p].mi=min(tr[lct][p<<].mi,tr[lct][p<<|].mi);
tr[lct][p].mx=max(tr[lct][p<<].mx,tr[lct][p<<|].mx);
}
else
{
tr[lct][p].mi=min(tr[lct<<][p].mi,tr[lct<<|][p].mi);
tr[lct][p].mx=max(tr[lct<<][p].mx,tr[lct<<|][p].mx);
}
}
void build_fir(int p,int l,int r)
{
if (l==r)
{
build_sec(p,,,n,l);
return;
}
int mid=(l+r)>>;
build_fir(p<<,l,mid),build_fir(p<<|,mid+,r);
build_sec(p,,,n,);
}
int query_mi2(int lct,int p,int l,int r,int x,int y)
{
if (l==x&&y==r) return tr[lct][p].mi;
int mid=(l+r)>>;
if (y<=mid) return query_mi2(lct,p<<,l,mid,x,y);
else if (x>mid) return query_mi2(lct,p<<|,mid+,r,x,y);
else return min(query_mi2(lct,p<<,l,mid,x,mid),query_mi2(lct,p<<|,mid+,r,mid+,y));
}
int query_mi1(int p,int l,int r,int x,int y,int x1,int y1)
{
if (l==x&&r==y) return query_mi2(p,,,n,x1,y1);
int mid=(l+r)>>;
if (y<=mid) return query_mi1(p<<,l,mid,x,y,x1,y1);
else if (x>mid) return query_mi1(p<<|,mid+,r,x,y,x1,y1);
else return min(query_mi1(p<<,l,mid,x,mid,x1,y1),query_mi1(p<<|,mid+,r,mid+,y,x1,y1));
}
int query_mx2(int lct,int p,int l,int r,int x,int y)
{
if (l==x&&y==r) return tr[lct][p].mx;
int mid=(l+r)>>;
if (y<=mid) return query_mx2(lct,p<<,l,mid,x,y);
else if (x>mid) return query_mx2(lct,p<<|,mid+,r,x,y);
else return max(query_mx2(lct,p<<,l,mid,x,mid),query_mx2(lct,p<<|,mid+,r,mid+,y));
}
int query_mx1(int p,int l,int r,int x,int y,int x1,int y1)
{
if (l==x&&r==y) return query_mx2(p,,,n,x1,y1);
int mid=(l+r)>>;
if (y<=mid) return query_mx1(p<<,l,mid,x,y,x1,y1);
else if (x>mid) return query_mx1(p<<|,mid+,r,x,y,x1,y1);
else return max(query_mx1(p<<,l,mid,x,mid,x1,y1),query_mx1(p<<|,mid+,r,mid+,y,x1,y1));
}
void update(int lct,int p,int l,int r,int x)
{
tr[lct][p].mi=min(tr[lct<<][p].mi,tr[lct<<|][p].mi);
tr[lct][p].mx=max(tr[lct<<][p].mx,tr[lct<<|][p].mx);
if (l==r)return;
int mid=(l+r)>>;
if (x<=mid) update(lct,p<<,l,mid,x);
else update(lct,p<<|,mid+,r,x);
}
void modify_sec(int lct,int p,int l,int r,int x,int z)
{
if (l==r){tr[lct][p].mi=tr[lct][p].mx=z;return;}
int mid=(l+r)>>;
if (x<=mid) modify_sec(lct,p<<,l,mid,x,z);
else modify_sec(lct,p<<|,mid+,r,x,z);
tr[lct][p].mi=min(tr[lct][p<<].mi,tr[lct][p<<|].mi);
tr[lct][p].mx=max(tr[lct][p<<].mx,tr[lct][p<<|].mx);
}
void modify_fir(int p,int l,int r,int x,int y,int z)
{
if(l==r){modify_sec(p,,,n,y,z);return;}
int mid=(l+r)>>;
if (x<=mid)modify_fir(p<<,l,mid,x,y,z);
else modify_fir(p<<|,mid+,r,x,y,z);
update(p,,,n,y);
}
int main()
{
freopen("fzy.in","r",stdin);
freopen("fzy.out","w",stdout); int T=read(),Case=;
while(T--)
{
printf("Case #%d:\n",++Case);
n=read();
for (int i=;i<=n;i++)
for (int j=;j<=n;j++)
a[i][j]=read();
build_fir(,,n);
m=read();
for (int i=;i<=m;i++)
{
int x=read(),y=read(),z=read()/;
int x1=max(x-z,),x2=min(x+z,n),y1=max(y-z,),y2=min(y+z,n);
int ansmi=query_mi1(,,n,x1,x2,y1,y2);
int ansmx=query_mx1(,,n,x1,x2,y1,y2);
int ans=(ansmx+ansmi)/;
printf("%d\n",ans);
modify_fir(,,n,x,y,ans);
}
}
}
hdu 4819 Mosaic 树套树 模板的更多相关文章
- HDU 4819 Mosaic D区段树
连接:pid=4819">http://acm.hdu.edu.cn/showproblem.php?pid=4819 意:给出一个800×800下面的矩阵.每次更新一个点的值为以这个 ...
- HDU 4819 Mosaic(13年长春现场 二维线段树)
HDU 4819 Mosaic 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4819 题意:给定一个n*n的矩阵,每次给定一个子矩阵区域(x,y,l) ...
- hdu 4819 二维线段树模板
/* HDU 4819 Mosaic 题意:查询某个矩形内的最大最小值, 修改矩形内某点的值为该矩形(Mi+MA)/2; 二维线段树模板: 区间最值,单点更新. */ #include<bits ...
- hdu 4417 Super Mario/树套树
原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=4417 题意很简单,给定一个序列求一个区间 [L, R,]中小于等于H的元素的个数. 好像函数式线段树可 ...
- P3380 【模板】二逼平衡树(树套树)(线段树套平衡树)
P3380 [模板]二逼平衡树(树套树) 前置芝士 P3369 [模板]普通平衡树 线段树套平衡树 这里写的是线段树+splay(不吸氧竟然卡过了) 对线段树的每个节点都维护一颗平衡树 每次把给定区间 ...
- 洛谷 P3380 bzoj3196 Tyvj1730 【模板】二逼平衡树(树套树)
[模板]二逼平衡树(树套树) 题目描述 您需要写一种数据结构(可参考题目标题),来维护一个有序数列,其中需要提供以下操作: 查询k在区间内的排名 查询区间内排名为k的值 修改某一位值上的数值 查询k在 ...
- 洛谷P3380 【模板】二逼平衡树(树套树)(线段树+树状数组)
P3380 [模板]二逼平衡树(树套树) 题目描述 您需要写一种数据结构(可参考题目标题),来维护一个有序数列,其中需要提供以下操作: 查询k在区间内的排名 查询区间内排名为k的值 修改某一位值上的数 ...
- 【Luogu】P3380树套树模板(线段树套Splay)
题目链接 幸甚至哉,歌以咏志. 拿下了曾经是那么遥不可及的线段树,学会了曾经高不可攀的平衡树,弄懂了装B的时候才挂在嘴边的树套树. 每道模板都是链上的一颗珠子.把它们挨个串起来,就成为我成长的历程. ...
- 洛谷 P3380 【模板】二逼平衡树(树套树)-线段树套splay
P3380 [模板]二逼平衡树(树套树) 题目描述 您需要写一种数据结构(可参考题目标题),来维护一个有序数列,其中需要提供以下操作: 查询k在区间内的排名 查询区间内排名为k的值 修改某一位值上的数 ...
随机推荐
- sqlserver数据库备份方法
须事先准备一个工具curl,把它放在c盘.然后,在数据库所在服务器安装7z.最后把这2个存储过程执行,在sqlserver的代理中新建作业,即可实现备份操作. --备份指定数据库到本地和远程指定位置( ...
- Servlet The Filter
The Filter Filter不会产生Request或者是Response, 但是会在两者访问资源时, 对其作出改变.其可以作用于静态资源和动态资源. LifeCycle Filter会和Serv ...
- Tensorflow_入门学习_1
1.0 TensorFlow graphs Tensorflow是基于graph based computation: 如: a=(b+c)∗(c+2) 可分解为 d=b+c e=c+2 a=d∗e ...
- Luogu P5351 Ruri Loves Maschera
先ORZ\(Owen\)一发.感觉是个很套路的题,这里给一个蒟蒻的需要特判数据的伪\(n\log^2 n\)算法,真正的两只\(\log\)的还是去看标算吧(但这个好想好写跑不满啊) 首先这种树上路径 ...
- ES6新增"Promise"可避免回调地狱
Promise是一个构造函数,自己身上有all.reject.resolve这几个眼熟的方法,原型上有then.catch等同样很眼熟的方法. 那就new一个 var p = new Promise( ...
- Tarjan求强联通分量+缩点
提到Tarjan算法就不得不提一提Tarjan这位老人家 Robert Tarjan,计算机科学家,以LCA.强连通分量等算法闻名.他拥有丰富的商业工作经验,1985年开始任教于普林斯顿大学.Tarj ...
- iOS开发遇见的坑之二:工程文件中插件和自身工程命名冲突
在升级cocoapod后,我重新管理了一下工程,其实也就是把各个类分类进行管理 类似于这样 然后编译就发现不能运行 1.其中一个错误是工程文件缺失,根据提示添加进来进行 2.有一个是pch的相对路径变 ...
- styled-components
参考: http://www.alloyteam.com/2017/05/guide-styled-components/ https://medium.com/styled-components/g ...
- axure笔记--变量值在页面之间的传递
fx 先给局部变量赋值,再添加到上面,即给全局变量赋值. 实现页面跳转: 1.打开链接,选择要跳转的下个页面---确定 2.打开那个下一个跳转的页面,要得到上个页面的值,需要到页面交互---页 ...
- [php扩展] php安装扩展注意事项
添加扩展的时候注意此3项 用的编译器版本:VC11... 安装的php版本:x86/x64 是否线程安全:enabled / disabled