题意:

r行c列的全0矩阵   有三种操作 1 x1 y1 x2 y2 v子矩阵(x1,y1,x2,y2)所有元素增加v

              2 x1 y1 x2 y2 v子矩阵(x1,y1,x2,y2)所有元素设为v

              3 x1 y1 x2 y2 查询子矩阵元素的和、最小值、最大值

分析:线段树的区间更新 、把矩阵化为一维。

#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <vector>
#include <string>
#include <cctype>
#include <complex>
#include <cassert>
#include <utility>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
using namespace std;
typedef pair<int,int> PII;
typedef long long ll;
#define lson(x) ((x<<1))
#define rson(x) ((x<<1)|1)
#define INF 0x3f3f3f3f
const int N = ;
int r, c, m;
struct Node {
int l, r;
int sum, Max, Min, sumv, setv;
} node[ * N];
void pushup(int x) {
node[x].sum = node[lson(x)].sum + node[rson(x)].sum;
node[x].Max = max(node[lson(x)].Max, node[rson(x)].Max);
node[x].Min = min(node[lson(x)].Min, node[rson(x)].Min);
} void pushdown(int x) {
if (node[x].setv) {
node[lson(x)].sumv = node[rson(x)].sumv = ;
node[lson(x)].setv = node[rson(x)].setv = node[x].setv;
node[lson(x)].sum = (node[lson(x)].r - node[lson(x)].l + ) * node[x].setv;
node[rson(x)].sum = (node[rson(x)].r - node[rson(x)].l + ) * node[x].setv;
node[lson(x)].Max = node[lson(x)].Min = node[x].setv;
node[rson(x)].Max = node[rson(x)].Min = node[x].setv;
node[x].setv = ;
}
if (node[x].sumv) {
node[lson(x)].sumv += node[x].sumv;
node[rson(x)].sumv += node[x].sumv;
node[lson(x)].sum += (node[lson(x)].r - node[lson(x)].l + ) * node[x].sumv;
node[rson(x)].sum += (node[rson(x)].r - node[rson(x)].l + ) * node[x].sumv;
node[lson(x)].Max += node[x].sumv;
node[lson(x)].Min += node[x].sumv;
node[rson(x)].Max += node[x].sumv;
node[rson(x)].Min += node[x].sumv;
node[x].sumv = ;
}
} void build(int l, int r, int x) {
node[x].l = l; node[x].r = r;
if (l == r) {
node[x].sum = node[x].Max = node[x].Min = node[x].sumv = node[x].setv = ;
return;
}
int mid = (l + r) / ;
build(l, mid, lson(x));
build(mid + , r, rson(x));
pushup(x);
} void update_add(int l, int r, int v, int x) {
if (node[x].l >= l && node[x].r <= r) {
node[x].sumv += v;
node[x].sum += (node[x].r - node[x].l + ) * v;
node[x].Max += v;
node[x].Min += v;
return;
}
pushdown(x);
int mid = (node[x].l + node[x].r) / ;
if (l <= mid) update_add(l, r, v, lson(x));
if (r > mid) update_add(l, r, v, rson(x));
pushup(x);
} void update_set(int l, int r, int v, int x) {
if (node[x].l >= l && node[x].r <= r) {
node[x].setv = v;
node[x].sum = (node[x].r - node[x].l + ) * v;
node[x].Max = node[x].Min = v;
node[x].sumv = ;
return;
}
pushdown(x);
int mid = (node[x].l + node[x].r) / ;
if (l <= mid) update_set(l, r, v, lson(x));
if (r > mid) update_set(l, r, v, rson(x));
pushup(x);
} Node query(int l, int r, int x) {
Node ans; ans.sum = ; ans.Max = ; ans.Min = INF;
if (node[x].l >= l && node[x].r <= r) {
ans.sum = node[x].sum;
ans.Max = node[x].Max;
ans.Min = node[x].Min;
return ans;
}
pushdown(x);
int mid = (node[x].l + node[x].r) / ;
if (l <= mid) {
Node tmp = query(l, r, lson(x));
ans.sum += tmp.sum;
ans.Max = max(ans.Max, tmp.Max);
ans.Min = min(ans.Min, tmp.Min);
}
if (r > mid) {
Node tmp = query(l, r, rson(x));
ans.sum += tmp.sum;
ans.Max = max(ans.Max, tmp.Max);
ans.Min = min(ans.Min, tmp.Min);
}
return ans;
} int main() {
while (~scanf("%d%d%d", &r, &c, &m)) {
build(, r * c, );
int q, x1, y1, x2, y2, v;
while (m--) {
scanf("%d", &q);
if (q == ) {
scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
int sum = , Max = , Min = INF;
for (int i = x1; i <= x2; i++) {
Node ans = query((i-)* c + y1, (i-) * c + y2, );
sum += ans.sum;
Max = max(Max, ans.Max);
Min = min(Min, ans.Min);
}
printf("%d %d %d\n", sum, Min, Max);
}
else {
scanf("%d%d%d%d%d", &x1, &y1, &x2, &y2, &v);
for (int i = x1; i <= x2; i++) {
if (q == ) update_add((i-) * c + y1, (i-) * c + y2, v, );
else update_set((i-) * c + y1, (i-) * c + y2, v, );
}
}
}
}
return ;
}

uva11992-Fast Matrix Operations(区间增值、改值)的更多相关文章

  1. UVA11992 - Fast Matrix Operations(段树部分的变化)

    UVA11992 - Fast Matrix Operations(线段树区间改动) 题目链接 题目大意:给你个r*c的矩阵,初始化为0. 然后给你三种操作: 1 x1, y1, x2, y2, v ...

  2. [uva11992]Fast Matrix Operations(多延迟标记,二维线段树,区间更新)

    题目链接:https://vjudge.net/problem/UVA-11992 题意:n*m的矩阵,每次对一个子矩阵操作,有三种操作:加x,设置为x,查询.查询返回子矩阵和.最小值.最大值 n很小 ...

  3. UVA11992 Fast Matrix Operations

    思路 注意到最多20行,拆成20颗线段树即可 注意set标记清空左右儿子的add,不要清空自己的add,因为这个set操作之后可能还有add存在这个节点上 代码 #include <cstdio ...

  4. Fast Matrix Operations

    A Simple Problem with Integers 每次将区间向下更新,或是用之前的方法,统计当前节点到父节点处的覆盖数目. #include <cstdio> #include ...

  5. UVA 11992 - Fast Matrix Operations(段树)

    UVA 11992 - Fast Matrix Operations 题目链接 题意:给定一个矩阵,3种操作,在一个矩阵中加入值a,设置值a.查询和 思路:因为最多20列,所以全然能够当作20个线段树 ...

  6. Fast Matrix Operations(UVA)11992

    UVA 11992 - Fast Matrix Operations 给定一个r*c(r<=20,r*c<=1e6)的矩阵,其元素都是0,现在对其子矩阵进行操作. 1 x1 y1 x2 y ...

  7. uva 11992 Fast Matrix Operations 线段树模板

    注意 setsetset 和 addvaddvaddv 标记的下传. 我们可以控制懒惰标记的优先级. 由于 setsetset 操作的优先级高于 addaddadd 操作,当下传 setsetset ...

  8. luogu题解 UVA11992 【Fast Matrix Operations】

    题目链接: https://www.luogu.org/problemnew/show/UVA11992 题目大意: 一个r*c的矩阵,一开始元素都是0,然后给你m次三种操作,分别是将一个子矩阵中所有 ...

  9. UVa 11992 (线段树 区间修改) Fast Matrix Operations

    比较综合的一道题目. 二维的线段树,支持区间的add和set操作,然后询问子矩阵的sum,min,max 写完这道题也是醉醉哒,代码仓库里还有一份代码就是在query的过程中也pushdown向下传递 ...

  10. UVa 11992 Fast Matrix Operations (线段树,区间修改)

    题意:给出一个row*col的全0矩阵,有三种操作 1 x1 y1 x2 y2 v:将x1 <= row <= x2, y1 <= col <= y2里面的点全部增加v: 2 ...

随机推荐

  1. Guide to Database Migration from Microsoft SQL Server using MySQL Workbench

    http://mysqlworkbench.org/2012/07/migrating-from-ms-sql-server-to-mysql-using-workbench-migration-wi ...

  2. maven3.1.1适合搭配的jdk版本

    maven 可以帮助我们管理项目的jar 不同的版本对jdk的要求也不相同, 比如3.1.1就要搭配1.6或以上的jre但是1.7有的版本还是会有点问题 当maven所需的jre版本不对应时项目会报错 ...

  3. 扩展ExtJs 4.2.1 htmleditor 添加图片功能

    做项目的时候遇到这样一个问题,因为我是用ExtJs做的后台管理框架,所以当我使用ExtJs htmleditor 控件 的时候,发现没有图片上传的功能,于是我打算在网上找找有关的文章,居然真有人写过, ...

  4. jquery 数组和字典

    1 数组的创建 var arrayObj = new Array(); //创建一个数组 var arrayObj = new Array([size]); //创建一个数组并指定长度,注意不是上限, ...

  5. BZOJ 3173 [Tjoi2013] 最长上升子序列 解题报告

    这个题感觉比较简单,但却比较容易想残.. 我不会用树状数组求这个原排列,于是我只好用线段树...毕竟 Gromah 果弱马. 我们可以直接依次求出原排列的元素,每次找到最小并且最靠右的那个元素,假设这 ...

  6. The 6th Zhejiang Provincial Collegiate Programming Contest->Problem I:A Stack or A Queue?

    http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3210 题意:给出stack和queue的定义,一个是先进后出(FILO), ...

  7. #pragma预处理指令讲解

    在所有的预处理指令中,#Pragma 指令可能是最复杂的了,它的作用是设定编译器的状态或者是指示编译器完成一些特定的动作.#pragma指令对每个编译器给出了一个方法,在保持与C和C++语言完全兼容的 ...

  8. html5移动web开发实战必读书记

    原文  http://itindex.net/detail/50689-html5-移动-web 主题 HTML5 一.配置移动开发环境 1.各种仿真器.模拟器的下载安装 http://www.mob ...

  9. SDUT 2527 斗地主

    http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2527 思路 :以前的结训比赛,当时不会做,比完 ...

  10. Centos后台运行jar

    jar后台运行 nohup java -jar xx.jar >/dev/null & 此处的">/dev/null"作用是将终端输出信息输出到空洞中,即不保存 ...