HDU 1754 I hate it
2015-08-24 22:33
351 查看
//线段树,单点更新+区间求和
AC代码:
AC代码:
#include<stdio.h> #include<string.h> #include<algorithm> using namespace std; #define lson l,m,rt<<1 #define rson m+1,r,rt<<1|1 const int MAX=200005; int sum[MAX<<2]; char s[8]; void push(int rt) { sum[rt]=max(sum[rt<<1],sum[rt<<1|1]); } void build(int l,int r,int rt) { if(l==r) { scanf("%d",&sum[rt]); return; } int m=(l+r)>>1; build(lson); build(rson); push(rt); } void updata(int p,int add,int l,int r,int rt) { if(l==r) { sum[rt]=add; return; } int m=(l+r)>>1; if(p<=m) updata(p,add,lson); else updata(p,add,rson); push(rt); } int querty(int L,int R,int l,int r,int rt) { if(L<=l&&R>=r) { return sum[rt]; } int m=(l+r)>>1; int t=-1<<29; if(L<=m) t=max(t,querty(L,R,lson)); if(R>m) t=max(t,querty(L,R,rson)); return t; } int main() { int n,m; while(scanf("%d%d",&n,&m)!=EOF) { build(1,n,1); int i; int x,y; for(i=0;i<m;i++) { scanf("%s%d%d",s,&x,&y); if(s[0]=='Q') { printf("%d\n",querty(x,y,1,n,1)); } if(s[0]=='U') { updata(x,y,1,n,1); } } } return 0; }
相关文章推荐
- HTTP 协议简介
- 黑马程序员_反射
- Class to connect postgres with python in psycopg2
- .Net分布式异常报警系统-服务端Service
- Android Studio编译时间过长问题解决
- Android UI设计——ListView控件和ArrayAdapter适配器(二)
- Android布局解析,图文(转)
- sql 简单的定义变量 声明 输出
- 用树莓派做FTP服务器
- UI_UIView基础知识
- scrum学习理解-看板工具选择
- mfc 单文档 多窗口,窗口控件刷新问题
- Scala学习笔记--apply用法
- Python实现读取目录所有文件的文件名并保存到txt文件代码
- 2015-08-24 周一 与jl谈话
- 关系型与非关系型数据介绍
- 黑马程序员_设计模式
- Andio Studio
- 用Ajax删除的做法
- .Net分布式异常报警系统-客户端及服务端API