UVALive - 6709
二维线段树单点修改板子题
#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的更多相关文章
- UVALive 6709 - Mosaic 二维线段树
题目链接 给一个n*n的方格, 每个方格有值. 每次询问, 给出三个数x, y, l, 求出以x, y为中心的边长为l的正方形内的最大值与最小值, 输出(maxx+minn)/2, 并将x, y这个格 ...
- UVALive - 6709树套树
题意:给你一个矩阵,q次操作,每次查询长宽l的矩阵最大值a和最小值b,然后把中间点换成floor((a+b)/2), 解法:暴力可过,建n颗线段树暴力更新,但是正解应该是树套树,树套树需要注意的是当建 ...
- UVALive - 4108 SKYLINE[线段树]
UVALive - 4108 SKYLINE Time Limit: 3000MS 64bit IO Format: %lld & %llu Submit Status uDebug ...
- UVALive - 3942 Remember the Word[树状数组]
UVALive - 3942 Remember the Word A potentiometer, or potmeter for short, is an electronic device wit ...
- UVALive - 3942 Remember the Word[Trie DP]
UVALive - 3942 Remember the Word Neal is very curious about combinatorial problems, and now here com ...
- 思维 UVALive 3708 Graveyard
题目传送门 /* 题意:本来有n个雕塑,等间距的分布在圆周上,现在多了m个雕塑,问一共要移动多少距离: 思维题:认为一个雕塑不动,视为坐标0,其他点向最近的点移动,四舍五入判断,比例最后乘会10000 ...
- UVALive 6145 Version Controlled IDE(可持久化treap、rope)
题目链接:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_ ...
- UVALive 6508 Permutation Graphs
Permutation Graphs Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu Submit ...
- UVALive 6500 Boxes
Boxes Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu Submit Status Pract ...
随机推荐
- 【转】MPU6050的数据获取、分析与处理
摘要 MPU6050是一种非常流行的空间运动传感器芯片,可以获取器件当前的三个加速度分量和三个旋转角速度.由于其体积小巧,功能强大,精度较高,不仅被广泛应用于工业,同时也是航模爱好者的神器,被安装在各 ...
- BZOJ1185 [HNOI2007]最小矩形覆盖 【旋转卡壳】
题目链接 BZOJ1185 题解 最小矩形一定有一条边在凸包上,枚举这条边,然后旋转卡壳维护另外三个端点即可 计算几何细节极多 维护另外三个端点尽量不在这条边上,意味着左端点尽量靠后,右端点尽量靠前, ...
- 【CF884D】Boxes And Balls k叉哈夫曼树
题目大意:给定一个大小为 N 的集合,每次可以从中挑出 2 个或 3 个数进行合并,合并的代价是几个数的权值和,求将这些数合并成 1 个的最小代价是多少. 引理:K 叉哈夫曼树需要保证 \((n-1) ...
- Linux上防火墙开放对应的端口
在Linux上防火墙开放对应的端口的命令如下: 方式一: [root@localhost sbin]# /sbin/iptables -I INPUT -p tcp --dport 80 -j ACC ...
- maven项目添加mysql的链接驱动
Maven项目中添加JDBC驱动 在pom.xml配置文件中添加: <dependency> <groupId>mysql</groupId> <arti ...
- debian8.4 ibus中文输入法
安装IBus: # apt-get install ibus ibus-sunpinyin ibus-table-wubi 导入输入法: 在Activities->Applications-&g ...
- Vue单页面应用阻止浏览器记住密码
Vue单页面应用阻止浏览器记住密码 ——IT唐伯虎 摘要: Vue单页面应用阻止浏览器记住密码. 现象1:路由切换时再次提示“是否记住密码” 登录页面有个密码输入框,输入账号密码进行登录: 登录完成后 ...
- hdu 5290 Bombing plan
http://acm.hdu.edu.cn/showproblem.php?pid=5290 题意: 一棵树,每个点有一个权值wi,选择点i即可破坏所有距离点i<=wi的点,问破坏所有点 最少需 ...
- ngx_lua_API 指令详解(五)coroutine.create,coroutine.resume,coroutine.yield 等集合指令介绍
ngx_lua 模块(原理实现) 1.每个worker(工作进程)创建一个Lua VM,worker内所有协程共享VM: 2.将Nginx I/O原语封装后注入 Lua VM,允许Lua代码直接访问: ...
- .NET面试题系列(六)多线程
1.多线程的三个特性:原子性.可见性.有序性 原子性:是指一个操作是不可中断的.即使是多个线程一起执行的时候,一个操作一旦开始,就不会被其他线程干扰. 比如,对于一个静态全局变量int i,两个线程同 ...