二维线段树单点修改板子题

 #include<bits/stdc++.h>
#define LL long long
#define fi first
#define se second
#define mk make_pair
#define pii pair<int,int>
#define piii pair<int, pair<int,int>>
using namespace std; const int N=+;
const int M=1e4+;
const int inf=0x3f3f3f3f;
const LL INF=0x3f3f3f3f3f3f3f3f;
const int mod=1e9 + ; int n, q, ans1, ans2, mx[N << ][N << ], mn[N << ][N << ], Map[N][N]; void subBuild(int op, int pos, int l, int r, int rt) {
mx[pos][rt] = -inf;
mn[pos][rt] = inf;
if(l == r) {
if(!op) {
scanf("%d", &mn[pos][rt]);
mx[pos][rt] = mn[pos][rt];
} else {
mn[pos][rt] = min(mn[pos << ][rt], mn[pos << | ][rt]);
mx[pos][rt] = max(mx[pos << ][rt], mx[pos << | ][rt]);
}
return;
}
int mid = l + r >> ;
subBuild(op, pos, l, mid, rt << );
subBuild(op, pos, mid + , r, rt << | );
mn[pos][rt] = min(mn[pos][rt << ], mn[pos][rt << | ]);
mx[pos][rt] = max(mx[pos][rt << ], mx[pos][rt << | ]);
}
void build(int l, int r, int rt) {
if(l == r) {
subBuild(, rt, , n, );
return;
}
int mid = l + r >> ;
build(l, mid, rt << );
build(mid + , r, rt << | );
subBuild(, rt, , n, );
} void subUpdate(int op, int pos, int y, int v, int l,int r,int rt) {
if(l == r) {
if(!op) mn[pos][rt] = mx[pos][rt] = v;
else {
mn[pos][rt] = min(mn[pos << ][rt], mn[pos << | ][rt]);
mx[pos][rt] = max(mx[pos << ][rt], mx[pos << | ][rt]);
}
return;
}
int mid = l + r >> ;
if(y <= mid) subUpdate(op, pos, y, v, l, mid, rt << );
else subUpdate(op, pos, y, v, mid + ,r, rt << | );
mn[pos][rt] = min(mn[pos][rt << ], mn[pos][rt << | ]);
mx[pos][rt] = max(mx[pos][rt << ], mx[pos][rt << | ]);
}
void update(int x, int y, int v, int l, int r, int rt) {
if(l == r) {
subUpdate(, rt, y, v, , n, );
return;
}
int mid = l + r >> ;
if(x <= mid) update(x, y, v, l, mid, rt << );
else update(x, y, v, mid + , r, rt << | );
subUpdate(, rt, y, v, , n, );
} void subQuery(int L, int R, int pos, int l, int r, int rt) {
if(l >= L && r <= R) {
ans1 = min(ans1, mn[pos][rt]);
ans2 = max(ans2, mx[pos][rt]);
return;
}
int mid = l + r >> ;
if(L <= mid) subQuery(L, R, pos, l, mid , rt << );
if(R > mid) subQuery(L, R, pos, mid + , r, rt << | );
}
void query(int Lx, int Rx, int Ly, int Ry, int l, int r, int rt) {
if(l >= Lx && r <= Rx) {
subQuery(Ly, Ry, rt, , n, );
return;
}
int mid = l + r >> ;
if(Lx <= mid) query(Lx, Rx, Ly, Ry, l, mid, rt << );
if(Rx > mid) query(Lx, Rx, Ly, Ry, mid + , r, rt << | );
}
int main() {
int T; scanf("%d", &T);
for(int cas = ; cas <= T; cas++) {
printf("Case #%d:\n", cas);
scanf("%d", &n);
build(, n, );
scanf("%d", &q);
while(q--) {
int x, y, w; scanf("%d%d%d", &x, &y, &w);
w >>= ;
int r1 = max(, x - w);
int r2 = min(n, x + w);
int c1 = max(, y - w);
int c2 = min(n, y + w);
ans1 = inf, ans2 = -inf;
query(r1, r2, c1, c2, , n, );
printf("%d\n", ans1 + ans2 >> );
update(x, y, ans1 + ans2 >> , , n, );
}
}
return ;
}
/*
*/

UVALive - 6709的更多相关文章

  1. UVALive 6709 - Mosaic 二维线段树

    题目链接 给一个n*n的方格, 每个方格有值. 每次询问, 给出三个数x, y, l, 求出以x, y为中心的边长为l的正方形内的最大值与最小值, 输出(maxx+minn)/2, 并将x, y这个格 ...

  2. UVALive - 6709树套树

    题意:给你一个矩阵,q次操作,每次查询长宽l的矩阵最大值a和最小值b,然后把中间点换成floor((a+b)/2), 解法:暴力可过,建n颗线段树暴力更新,但是正解应该是树套树,树套树需要注意的是当建 ...

  3. UVALive - 4108 SKYLINE[线段树]

    UVALive - 4108 SKYLINE Time Limit: 3000MS     64bit IO Format: %lld & %llu Submit Status uDebug ...

  4. UVALive - 3942 Remember the Word[树状数组]

    UVALive - 3942 Remember the Word A potentiometer, or potmeter for short, is an electronic device wit ...

  5. UVALive - 3942 Remember the Word[Trie DP]

    UVALive - 3942 Remember the Word Neal is very curious about combinatorial problems, and now here com ...

  6. 思维 UVALive 3708 Graveyard

    题目传送门 /* 题意:本来有n个雕塑,等间距的分布在圆周上,现在多了m个雕塑,问一共要移动多少距离: 思维题:认为一个雕塑不动,视为坐标0,其他点向最近的点移动,四舍五入判断,比例最后乘会10000 ...

  7. UVALive 6145 Version Controlled IDE(可持久化treap、rope)

    题目链接:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_ ...

  8. UVALive 6508 Permutation Graphs

    Permutation Graphs Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Submit ...

  9. UVALive 6500 Boxes

    Boxes Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Submit Status Pract ...

随机推荐

  1. 【BZOJ1024】[SCOI2009]生日快乐(搜索)

    [BZOJ1024][SCOI2009]生日快乐(搜索) 题面 BZOJ 洛谷 题解 看到这个数据范围就感觉是爆搜.我们爆搜左右分成多少块,这样子左右的面积已知,再枚举一下横着切还是竖着切,这样子就可 ...

  2. asp.net中SQL语句太长,怎么换行写?

    http://bbs.csdn.net/topics/390639485?page=1 string strfac="insert into CarInfo values('"+T ...

  3. 项目实战SportsStore——订单处理模块

    前面的步骤如果顺利完成,你的网站运行之后应该能够正常显示下面三个页面: 1.产品列表 2.购物车内容页面 在某个商品后面点击“添加到购物车”则出现下图页面: 此页面上点击“继续购物”按钮则返回到产品列 ...

  4. LAMP平台-wordpress的搭建

    LAMP平台-wordpress的搭建 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. Linux+Apache+Mysql/MariaDB+Perl/PHP/Python一组常用来 ...

  5. 用Riffstation扒带

    有人说扒带本质就是扒和声 编曲初学者如果是自学的情况下很容易陷入瓶颈,网络上的编曲爱好者大都建议去多扒带,所谓扒带其实就是把别人的编曲自己编出来,然而这要很好的听力,下面我介绍的这款软件就是用来扒和声 ...

  6. C++ 多用户模式下同一个exe只能运行一次

    1.有时候会遇到多用户模式下一不小心会运行多个exe的问题,所以程序中添加一下代码解决这个问题: BOOL CtestDialogApp::InitInstance() { char exeFullP ...

  7. 命令行IRC

    安装客户端irffs sudo apt-get install irssi 登陆服务器 irssi -c irc.freenode.net 设置昵称 /nick <name> 注册或登陆 ...

  8. 用Canvas做动画

    之前看过不少HTML5动画的书,讲解的是如何去做,对于其中的数学原理讲解的不详细,常有困惑.最近看的<HTML5+JavaScript 动画基础>这个是译本,Keith Peters曾写过 ...

  9. Python super() 函数

    super() 函数是用于调用父类(超类)的一个方法. super 是用来解决多重继承问题的,直接用类名调用父类方法在使用单继承的时候没问题,但是如果重定义某个方法,该方法会覆盖父类的同名方法,但有时 ...

  10. 分模块开发创建dao子模块——(七)

    1.选中父工程右键新建maven module