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 ...
随机推荐
- 【刷题】LOJ 2818 「eJOI2018」循环排序
题目描述 本题译自 eJOI2018 Problem F「Cycle Sort」 给定一个长为 \(n\) 的数列 \(\{a_i\}\) ,你可以多次进行如下操作: 选定 \(k\) 个不同的下标 ...
- pat1001. Battle Over Cities - Hard Version 解题报告
/**题目:删去一个点,然后求出需要增加最小代价的边集合生成连通图思路:prim+最小堆1.之前图中未破坏的边必用,从而把两两之间可互达的点集合 合并成一个点2.求出不同点集合的最短距离,用prim+ ...
- POJ - 2299 Ultra-QuickSort(归并排序)
https://vjudge.net/problem/POJ-2299 题意 求对于给定的无序数组,求出经过最少多少次相邻元素的交换之后,可以使数组从小到大有序. 分析 很明显是求逆序对的数目,那就要 ...
- SQL语句(八)按条件查询
SELECT * FROM student SELECT sclass, snumb, sname FROM student --物理班有哪些同学 --年龄小于20岁的有哪些同学? --定价在30元以 ...
- 转自知乎大神----JS 闭包是什么
大名鼎鼎的闭包!这一题终于来了,面试必问. 请用自己的话简述 什么是「闭包」. 「闭包」的作用是什么. --------------------------------------- 首先来简述什么是 ...
- MySQL记录异常实体类设计
public class LogInfo { /// <summary> /// 应用名 /// </summary> public string AppName { get; ...
- 【LibreOJ】#6396. 「THUPC2018」弗雷兹的玩具商店 / Toyshop 线段树+完全背包
[题目]#6396. 「THUPC2018」弗雷兹的玩具商店 / Toyshop [题意]给定一个长度为n的物品序列,每个物品有价值.不超过m的重量.要求支持以下三种操作:1.物品价值区间加减,2.物 ...
- mac 无法验证副本
转: 这个是拆机后断了电源,导致时间不对,也就是说现在电脑的时间比U盘制作的时间还早,所以有这样的错误提示. 在终端里面修改时间请参考下面的代码,按回车键确认:date 062614102014.30 ...
- Replication监控及自动故障切换
首先在相应的机器上增加授权 GRANT REPLICATION SLAVE ON *.* TO 'repl'@'192.168.1.108' IDENTIFIED BY 'repl';GRANT RE ...
- 基于ZedBoard的Webcam设计(一):USB摄像头(V4L2接口)的图片采集【转】
转自:http://www.cnblogs.com/surpassal/archive/2012/12/19/zed_webcam_lab1.html 一直想把USB摄像头接到Zedboard上,搭建 ...