hdu 1166 敌兵布阵(线段树基本操作)
2012-08-22 15:20
477 查看
http://acm.hdu.edu.cn/showproblem.php?pid=1166
(1)纯属敲模版,没有什么特别的。错了两次:一次是TLE,原因是输出了不该输出的(测试用的,忘了删掉);另一次WA,原因是没有输出该输出的(cas)。
具体代码:
View Code
(1)纯属敲模版,没有什么特别的。错了两次:一次是TLE,原因是输出了不该输出的(测试用的,忘了删掉);另一次WA,原因是没有输出该输出的(cas)。
具体代码:
View Code
#include<stdio.h> #include<string.h> #include<algorithm> #define lson l, m, rt<<1 #define rson m+1, r, rt<<1|1 using namespace std; const int N=300000; int data , Max[N<<2]; int n, m; void pushup(int rt) { Max[rt]=max(Max[rt<<1], Max[rt<<1|1]); } void build(int l, int r, int rt) { if(l==r) { scanf("%d", &data[l]); Max[rt]=data[l]; return ; } int m=l+r>>1; build(lson); build(rson); pushup(rt); } int query(int L, int R, int l, int r, int rt) { if(L<=l&&r<=R) return Max[rt]; int m=l+r>>1; int ret=0; if(L<=m) ret=max(ret, query(L, R, lson)); if(R>m) ret=max(ret, query(L, R, rson)); return ret; } void update(int p, int val, int l, int r, int rt) { if(l==r) { data[l]=val; Max[rt]=data[l]; return ; } int m=l+r>>1; if(p<=m) update(p, val, lson); else update(p, val, rson); pushup(rt); } int main() { int i, j; int a, b; char ch; while(scanf("%d%d", &n, &m)!=EOF) { build(1, n, 1); for(i=1;i<=m;i++) { scanf(" %c%d%d", &ch, &a, &b); if(ch=='Q') { printf("%d\n", query(a, b, 1, n, 1)); } else { update(a, b, 1, n, 1); } } } return 0; }
相关文章推荐
- HDOJ 1166 敌兵布阵(线段树基本操作)
- HDU 1166 敌兵布阵 基本线段树
- HDU 1166 敌兵布阵 线段树的基本应用——动态区间和问题
- 杭电hdu 1166 敌兵布阵 线段树
- HDU 1166 —— 敌兵布阵 【树状数组 or 线段树】
- HDU 1166 敌兵布阵【线段树】
- HDU-1166 敌兵布阵(线段树模板题)
- HDU 1166----敌兵布阵(线段树点更新)
- HDU 1166 敌兵布阵 (线段树单点更新 区间查询)
- hdu 1166 敌兵布阵(线段树详解)
- hdu1166 敌兵布阵——(线段树模板)
- HDU-1166 敌兵布阵【简单线段树-单点更新+区间查询】
- hdu 1166 敌兵布阵(线段树,只更新叶子节点)
- HDU 1166 敌兵布阵【线段树 单点更新】
- HDU 1166 敌兵布阵(线段树)
- hdu--1166 敌兵布阵(线段树+单点更新和查询)
- HDU 1166 敌兵布阵(线段树单点更新)
- HDU-1166敌兵布阵(线段树)
- HDU-1166 敌兵布阵 线段树
- HDU 1166 敌兵布阵 线段树入门题目