hdu 1754 I Hate It (线段树版)
来源:互联网 发布:h5制作软件 编辑:程序博客网 时间:2024/06/08 05:12
题目链接:点击打开链接
读入的时候因为要先输入字符C,所以要用getchar()和输入时的%*c处理掉空格,很烦,不按字符输入而是%s输入字符串可避免这个问题
代码:
#include <iostream>#include <cstdio>using namespace std;#define lson l,m,rt<<1#define rson m+1,r,rt<<1|1#define MAX 200010int a[MAX<<2];void pushup(int rt){ a[rt]=max(a[rt<<1],a[rt<<1|1]);}void build(int l,int r,int rt){ if(l==r){ scanf("%d",&a[rt]); return; } else a[rt]=0; int m=(l+r)>>1; build(lson); build(rson); pushup(rt);}void update(int p,int n,int l,int r,int rt){ if(l==r){ a[rt]=n; return ; } int m=(l+r)>>1; if(p<=m)update(p,n,lson); else update(p,n,rson); pushup(rt);}int query(int L,int R,int l,int r,int rt){ if(L<=l&&R>=r){ return a[rt]; } int m=(l+r)>>1; int res=0; if(L<=m)res=max(res,query(L,R,lson)); if(R>m)res=max(res,query(L,R,rson)); return res;}int main(){ int n,m; while(~scanf("%d%d%*c",&n,&m)){ build(1,n,1); getchar(); for(int i=1;i<=m;i++){ char t; int s,e; scanf("%c%d%d%*c",&t,&s,&e); if(t=='Q'){ printf("%d\n",query(s,e,1,n,1)); } else update(s,e,1,n,1); } } return 0;}
0 0
- hdu 1754 I Hate It (线段树版)
- HDU 1754 I Hate It 线段树
- [hdu] 1754 I hate it -- 线段树
- hdu 1754 -- I Hate It (线段树)
- HDU 1754 I Hate It 线段树
- 线段树 hdu 1754 I Hate It
- HDU 1754 I Hate It(线段树)
- hdu 1754 (线段树)I Hate It
- hdu-1754 I Hate It 线段树
- HDU--1754 -- I Hate It [线段树]
- 【线段树】hdu 1754 I hate it
- hdu - 1754 I Hate It(线段树)
- HDU--1754--I Hate It--线段树
- HDU-1754 I Hate It 线段树
- hdu 1754 I Hate It 线段树
- HDU-1754-I Hate It(线段树)
- HDU 1754 I Hate It (线段树)
- hdu 1754 I hate it(线段树)
- Servlet 3.0笔记之异步请求Facebook BigPipe简单模型实现
- oracle系统权限列表(转)
- X API
- 复制source中的内容到target中
- 通过Intent 传递类对象
- hdu 1754 I Hate It (线段树版)
- 10、 java 编写一个截取字符串的函数,输入为一个字符串和字节数,输出为按字节截取的字符串。 要求不能出现截半的情况
- 美美洗衣房,看着就忍不住心情好
- poj 3414 Pots BFS
- Java学习—泛型方法
- ASP.net MVC分页实例
- Java基础总结——移位
- HDOJ 4923 Room and Moor(求方差、栈)
- SQL 视图 - view