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的值 修改某一位值上的数 ...
随机推荐
- 5 Options for Distributing Your iOS App to a Limited Audience
http://mobiledan.net/2012/03/02/5-options-for-distributing-ios-apps-to-a-limited-audience-legally/ I ...
- 解决response在controller返回乱码的解决方式
乱码的代码 @RequestMapping(value = "/readbook", method = RequestMethod.GET) 加入 produces = " ...
- 利用python实现整数转换为任意进制字符串
假设你想将一个整数转换为一个二进制和十六进制字符串.例如,将整数 10 转换为十进制字符串表示为 10 ,或将其字符串表示为二进制 1010 . 实现 以 2 到 16 之间的任何基数为参数: def ...
- python之编码的进阶
识记点: ascii 不支持中文 gbk 国标 中文2 英文1 unicode 万国码 英文2 中文4 utf-8 英文1 欧洲2 亚洲3 硬盘中存储的是字节 用什么编码就用什么解码 # 一段文字的转 ...
- SniperOJ-leak-x86-64
参考:1.借助DynELF实现无libc的漏洞利用小结 2.一步一步学ROP之linux_x64篇 - 蒸米 题目源码 #include <stdio.h> #include <un ...
- PAT (Advanced Level) Practise - 1099. Build A Binary Search Tree (30)
http://www.patest.cn/contests/pat-a-practise/1099 A Binary Search Tree (BST) is recursively defined ...
- word2vec 中的数学原理详解(二)预备知识
版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/peghoty/article/details/37969635 https://blog.csdn. ...
- IE(IE6/IE7/IE8)支持HTML5标签--20150216
让IE(ie6/ie7/ie8)支持HTML5元素,我们需要在HTML头部添加以下JavaScript,这是一个简单的document.createElement声明,利用条件注释针对IE来调用这个j ...
- 无法解析具体reference那个同名文件
公司平台,如果src和gen文件系统中有同名文件.reference时会根据depend.cfg文件优先reference遇到的同名文件.这样如果存在同名文件且引用顺序不对就会有莫名的bug. 像rt ...
- bash初识,特性,用法/网站
目录 一.Bash初识 Bash Shell介绍 Bash Shell的作用 Bash 两种方式 命令提示符 二.Shell的基本语法 三.Shell的基本特性 1.命令补全 tab 2. Linux ...