题意:

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. 跨过slf4j和logback,直接晋级log4j 2

    今年一直关注log4j 2,但至今还没有出正式版.等不及了,今天正式向大家介绍一下log4j的升级框架,log4j 2. log4j,相信大家都熟悉,至今对java影响最大的logging系统,至今仍 ...

  2. 1037: [ZJOI2008]生日聚会Party - BZOJ

    Description 今天是hidadz小朋友的生日,她邀请了许多朋友来参加她的生日party. hidadz带着朋友们来到花园中,打算坐成一排玩游戏.为了游戏不至于无聊,就座的方案应满足如下条件: ...

  3. sequel 连接不上,命令行能连上

    Sequel pro won't connect anymore I'm running into some trouble right now. I worked yesterday on my d ...

  4. NIO的Selector

    参考自 Java NIO系列教程(六) Selector Java-NIO-Selector java.nio.channels.Selector NIO新功能Top 10(下) 出发点: 如何管理多 ...

  5. Error building Player: CommandInvokationFailure: Failed to re-package resources. See the Console for details. ShareSDK 也有这种错误

    Error building Player: CommandInvokationFailure: Failed to re-package resources. See the Console for ...

  6. 关于static继承的问题

    c++primer 15.2.7节关于static继承的意思是,父类和子类共享static函数或者static成员变量,并且子类要访问还要受它们的权限限制,下面是看到的另一个例子 class Base ...

  7. ASP.NET 访问 MySql

    1. 首先需要安装mysql, 脚本之家下载地址: http://www.jb51.net/softs/2193.html 或者去mysql.com官网都可以,一路next,安装好后,有个简单配置,提 ...

  8. 跨平台的目录遍历实现方法(windows和linux已经测试)

    dirent.h是gcc下的一个头文件,在windows中是没有的.这个文件中封装了几个对目录进行操作函数: static DIR *opendir (const char *dirname);sta ...

  9. python string 连接test

    def strTest(): name = "" for i in range(10): name += "hello" #print name def str ...

  10. MyBatis的动态SQL操作--删除

    aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAUYAAAC/CAIAAAANX+LCAAAYvElEQVR4nO2dWWycV9nHDyC6UEGBGy