UVA 11992 Fast Matrix Operations
来源:互联网 发布:狗听得懂人话吗 知乎 编辑:程序博客网 时间:2024/04/28 11:59
线段树区间修改,懒标记传递。
#include<bits/stdc++.h>#define INF 0x3f3f3f3f#define lson o<<1#define rson o<<1|1using namespace std;const int MAXN = 1<<17;int x, ql, qr, op;struct node { int addv, setv, sumv, minv, maxv;};node better(node a, node b) { node ret; ret.sumv = a.sumv + b.sumv; ret.minv = min(a.minv, b.minv); ret.maxv = max(a.maxv, b.maxv); return ret;}struct Intervaltree { node a[MAXN]; void clear(int n) { for(int i = 1; i <= MAXN; i++) { a[i].addv = a[i].maxv = a[i].minv = a[i].sumv = 0; a[i].setv = -1; } a[1].setv = 0; } void mantain(int o, int l, int r) { if(r > l) { a[o].sumv = a[lson].sumv + a[rson].sumv; a[o].minv = min(a[lson].minv, a[rson].minv); a[o].maxv = max(a[lson].maxv, a[rson].maxv); } if(a[o].setv >= 0) { a[o].minv = a[o].maxv = a[o].setv; a[o].sumv = a[o].setv*(r-l+1); } a[o].minv += a[o].addv, a[o].maxv += a[o].addv; a[o].sumv += a[o].addv*(r-l+1); } void pushdown(int o) { if(a[o].setv >= 0) { a[lson].setv = a[rson].setv = a[o].setv; a[o].setv = -1; a[lson].addv = a[rson].addv = 0; } if(a[o].addv) { a[lson].addv += a[o].addv; a[rson].addv += a[o].addv; a[o].addv = 0; } } void update(int o, int l, int r) { if(ql<=l && qr>=r) { if(op == 1) a[o].addv += x; else a[o].setv = x, a[o].addv = 0; } else { pushdown(o); int m = l+r>>1; if(ql <= m) update(lson, l, m); else mantain(lson, l, m); if(m+1 <= qr) update(rson, m+1, r); else mantain(rson, m+1, r); } mantain(o, l, r); } node query(int o, int l, int r, int add) { node t; if(a[o].setv >= 0) { int tmp = a[o].setv + a[o].addv + add; t.sumv = tmp*(min(qr, r)-max(l, ql)+1); t.minv = t.maxv = tmp; return t; } if(ql<=l && qr>=r) { t.sumv = a[o].sumv + add*(r-l+1); t.minv = a[o].minv + add; t.maxv = a[o].maxv + add; return t; } int m = l+r>>1; if(m >= qr) return query(lson, l, m, add+a[o].addv); if(m+1 <= ql) return query(rson, m+1, r, add+a[o].addv); return better(query(lson, l, m, add+a[o].addv), query(rson, m+1, r, add+a[o].addv)); }}tree[25];int main() { int n, m, q; while(scanf("%d%d%d", &n, &m, &q) == 3) { for(int i = 1; i <= n; i++) tree[i].clear(m); while(q--) { int x1, x2; scanf("%d%d%d%d%d", &op, &x1, &ql, &x2, &qr); if(op < 3) { scanf("%d", &x); for(int i = x1; i <= x2; i++) tree[i].update(1, 1, m); } else { node t = tree[x1].query(1, 1, m, 0); for(int i = x1+1; i <= x2; i++) t = better(t, tree[i].query(1, 1, m, 0)); printf("%d %d %d\n", t.sumv, t.minv, t.maxv); } } } return 0;}
0 0
- Uva-11992-Fast Matrix Operations
- UVA 11992 Fast Matrix Operations
- Fast Matrix Operations ,uva 11992
- UVA 11992 Fast Matrix Operations
- UVA - 11992 Fast Matrix Operations
- UVa:11992 Fast Matrix Operations
- UVA 11992Fast Matrix Operations
- UVA 11992 - Fast Matrix Operations
- UVa 11992 Fast Matrix Operations
- uva 11992 Fast Matrix Operations
- UVA 11992 Fast Matrix Operations
- Uva 11992 Fast Matrix Operations
- UVA 11992 Fast Matrix Operations
- uva 11992 Fast Matrix Operations(线段树)
- UVa 11992 Fast Matrix Operations 线段树
- UVA 11992 - Fast Matrix Operations(线段树)
- uva 11992 Fast Matrix Operations 线段树
- uva 11992 - Fast Matrix Operations(线段树)
- 高性能的关键:Spring MVC的异步模式
- 【视频】BSR缺陷引起的上行流量问题
- 春节将至,为何我如此“恐归”
- LeetCode 387. First Unique Character in a String
- Codeforces 758B-Blown Garland
- UVA 11992 Fast Matrix Operations
- hdu1512 Monkey King
- 【清明】搜索
- css中absolute使用,用position和transform是div里面的div垂直居中
- Android编程权威指南(第二版)学习笔记(十九)—— 第19章 使用 SoundPool 播放音频
- 剪裁头像裁剪遇到关于小米华为适配问题的解决
- PAT---B1036. 跟奥巴马一起编程(15)
- Windows驱动程序学习步骤
- 单片机学习