hdoj 1698 Just a Hook
来源:互联网 发布:sql身份证取性别 编辑:程序博客网 时间:2024/05/18 01:20
类型:一维线段树
来源:2008 “Sunline Cup” National Invitational Contest
题目:线段更新【颜色下移】,求区间最大值
// hdoj 1698 Just a Hook// wa ac 437MS1416K#include <iostream>#include <cstdio>#include <cstring>using namespace std;#define FOR(i,a,b) for(i = (a); i < (b); ++i)#define FORE(i,a,b) for(i = (a); i <= (b); ++i)#define CLR(a,b) memset(a,b,sizeof(a))const int MAXN = 100000;const int INF = 0x7f7f7f7f;int cas, n, sum, m;int tree[MAXN * 3];void build(int root, int l, int r) { if(l == r) { tree[root] = 1; return ; } int mid = (l + r) >> 1; build(root << 1, l, mid); build(root << 1 | 1, mid + 1, r);}void insert(int root, int l, int r, int x1, int x2, int col) { if(l == x1 && r == x2) { tree[root] = col; return ; } if(tree[root] != 0) { tree[root << 1] = tree[root << 1 | 1] = tree[root]; tree[root] = 0; } int mid = (l + r) >> 1; if(mid >= x2) insert(root << 1, l, mid, x1, x2, col); else if(mid < x1) insert(root << 1 | 1, mid + 1, r, x1, x2, col); else { insert(root << 1, l, mid, x1, mid, col); insert(root << 1 | 1, mid + 1, r, mid + 1, x2, col); }}void cal(int root, int l, int r, int x1, int x2) { int i; if(l == x1 && r == x2 && tree[root] != 0) { FORE(i, l, r) sum += tree[root]; return ; } int mid = (l + r) >> 1; if(mid >= x2) cal(root << 1, l, mid, x1, x2); else if(mid < x1) cal(root << 1 | 1, mid + 1, r, x1, x2); else { cal(root << 1, l, mid, x1, mid); cal(root << 1 | 1, mid + 1, r, mid + 1, x2); }}int main(){ int i, a, b, c, d; int nnn = 1; scanf("%d", &cas); while(cas--) { CLR(tree, 0); scanf("%d", &n); build(1, 1, n); scanf("%d", &c); FOR(i, 0, c) { scanf("%d %d %d", &a, &b, &d); insert(1, 1, n, a, b, d); } sum = 0; cal(1, 1, n, 1, n); printf("Case %d: The total value of the hook is %d.\n", nnn++, sum); } return 0;}
- HDOJ 1698 Just a Hook
- hdoj 1698 Just a Hook
- hdoj 1698 Just a hook!
- HDOJ 1698 - Just a Hook
- HDOJ 1698 Just a Hook
- HDOJ 1698 Just a Hook
- HDOJ-1698 Just a Hook
- hdoj 1698 Just a Hook
- hdoj 1698 Just a Hook 【线段树】
- 【线段树】HDOJ 1698 Just a Hook
- hdoj 1698 Just a Hook【线段树】
- HDOJ 1698 Just a Hook [区间替换+区间查询]
- hdoj 1698--Just a Hook 线段树练习
- hdoj 1698 Just a Hook 【线段树 区间更新】
- HDOJ 1698 Just a Hook(区间更新)
- hdoj 1698 Just a Hook 【线段树区间修改】
- HDOJ 1698 Just a Hook (线段树)
- hdu 1698 Just a Hook
- MVC框架实现6---Smart框架ActionServlet控制器组件实现
- jdk安装完为什么会有两个JRE
- 项目管理知识体系42个过程
- 关于泛型的
- ril.cpp解析
- hdoj 1698 Just a Hook
- MAC支持exFAT
- QT新建进程
- AOP原理
- 标致携手《VISION视觉》与建筑师刘威畅想设计的未来
- 提高项目团队效能的六把金钥匙
- 解决ListView异步加载图片错乱问题
- sqlServer数据库驱动ip地址及端口的查看
- 项目成功的12个关键原则