HDU 1698 Just a Hook (线段树,区间更新)
来源:互联网 发布:js 禁用y轴滑动 编辑:程序博客网 时间:2024/04/29 22:16
HDU 1689
模板题。
#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>#include <queue>using namespace std;int N, Q;const int MAXN = 100100;struct node {int l, r, m, val, book;};node T[4 * MAXN];void build(int rt, int begin, int end) {T[rt].l = begin, T[rt].r = end, T[rt].m = (begin + end) >> 1, T[rt].book = 0;if(begin == end) {T[rt].val = 1;return;}build(rt << 1, begin, T[rt].m);build(rt << 1 | 1, T[rt].m + 1, end);T[rt].val = T[rt << 1].val + T[rt << 1 | 1].val;}void updata(int rt, int l, int r, int num) {if(l == T[rt].l && r == T[rt].r) {T[rt].book = num;T[rt].val = num * (T[rt].r - T[rt].l + 1);return;}if(T[rt].book) {T[rt << 1].book = T[rt].book;T[rt << 1 | 1].book = T[rt].book;T[rt << 1].val = T[rt].book * (T[rt << 1].r - T[rt << 1].l + 1);T[rt << 1 | 1].val = T[rt].book * (T[rt << 1 | 1].r - T[rt << 1 | 1].l + 1);T[rt].book = 0;}if(l > T[rt].m) updata(rt << 1 | 1, l, r, num);else if(r <= T[rt].m) updata(rt << 1, l, r, num);else {updata(rt << 1, l, T[rt].m, num);updata(rt << 1 | 1, T[rt].m + 1, r, num);}T[rt].val = T[rt << 1].val + T[rt << 1 | 1].val;}int main() {int t;while(~scanf("%d", &t)) {int k = 1;while(t--) {scanf("%d%d", &N, &Q);build(1, 1, N);int i;int x, y, z;for(i = 0; i < Q; i++) {scanf("%d %d %d", &x, &y, &z);updata(1, x, y, z);}printf("Case %d: The total value of the hook is %d.\n", k++, T[1].val);}} return 0;}
0 0
- 线段树(区间更新) hdu-1698-Just a Hook
- hdu 1698 Just a Hook(线段树-区间更新)
- HDU 1698 Just a Hook (线段树区间更新)
- HDU 1698 Just a Hook (线段树区间更新)
- HDU 1698 Just a Hook(线段树区间更新)
- HDU 1698 Just a Hook (线段树,区间更新)
- HDU 1698 Just a Hook (线段树区间更新)
- HDU 1698 Just a Hook(线段树---区间更新)
- Just a Hook (hdu 1698 线段树区间更新)
- HDU-1698 Just a Hook(线段树区间更新)
- HDU 1698 Just a Hook (线段树区间更新)
- HDU 1698 Just a Hook 线段树区间更新
- hdu 1698(区间更新线段树)Just a Hook
- hdu 1698 Just a Hook 线段树区间更新
- HDU-1698-Just a Hook(线段树 区间更新)
- hdu 1698 Just a Hook 线段树区间更新
- HDU 1698 Just a Hook (线段树区间更新)
- HDU 1698 Just a Hook(线段树区间更新)
- Missing required libmysql_e.dll
- opencv轮廓检测之椭圆检测-----算法篇(2)---Sobel---自定义卷积核问题
- 解决redhat自带yum不能用的问题 (借用CentOS)
- 二叉树中和为某一定值的路径
- int,long,long long范围
- HDU 1698 Just a Hook (线段树,区间更新)
- Cookie解释以及原理分析
- Application类注释
- 复杂链表的复制
- 工具使用之Github的SSH配置
- 解读OpenGL ES 2.0绘制一个三角形的步骤
- js--语法--for和for-in;访问对象的属性.和[]的区别
- QC ALM11安装
- 二叉搜索树 转 有序双向链表