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

 #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. MT【93】二次函数衣服一件

    注:最后一行中$f(\dfrac{-x_1}{2})$应改为$f(\dfrac{-a}{2})$.有空再重新编辑.

  2. Linux上SSH登录远程服务器免密码

    在本地的客户端SSH到远程服务端时,每次都要输入用户名和密码,如果不想每次都输入密码则可以使用以下操作. 首先在本地的客户端输入 ssh-keygen [keysystem@localhost ~]$ ...

  3. NodeJS API Process全局对象

    Process 全局对象,可以在代码中的任何位置访问此对象,使用process对象可以截获进程的异常.退出等事件,也可以获取进程的当前目录.环境变量.内存占用等信息,还可以执行进程退出.工作目录切换等 ...

  4. cookie添加删除修改

    //cookie添加 document.cookie="username=John Doe"; //添加过期时间 document.cookie="username1=J ...

  5. bzoj千题计划179:bzoj1237: [SCOI2008]配对

    http://www.lydsy.com/JudgeOnline/problem.php?id=1237 如果没有相同的数不能配对的限制 那就是排好序后 Σ abs(ai-bi) 相同的数不能配对 交 ...

  6. git 查看一个分支是否被合并过

    1.查看该分支的提交历史 git log 分支名 2.git log master |grep comitid 如果包含,就证明已经合并过 3.git branch -d 分支名,如果报错,就是没合并 ...

  7. mybatis mapper接口开发dao层

    本文将探讨使用 mapper接口,以及 pojo 包装类进行 dao 层基本开发 mybatis dao 层开发只写 mapper 接口 其中需要 开发的接口实现一些开发规范 1. UserMappe ...

  8. javascript实现的拖拽回放

    这个功能很简单,直接贴代码啊: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "ht ...

  9. 【两分钟教程】如何更改Xcode项目名称

    注意:视频在最后,还少了一个步骤:将Xcode中的名字叫做<企信通>的虚拟文件夹删掉,然后重新从硬盘中添加进来,这样就彻底完成了更改Xcode项目名称的目的.

  10. MFS - MooseFS 文件系统

    MFSMooseFS 文件系统 可以实现RAID 功能:节约成本 实现在线扩展:是一种半分布式文件系统. 一.MFS文件系统的组成 1.mfsmaster 元数据服务器. 在整个体系中负责管理管理文件 ...