HDU 1754 I Hate It
来源:互联网 发布:java如何执行cmd命令 编辑:程序博客网 时间:2024/06/05 00:55
本题是一个简单的线段树 与hdu的1166题相似
树状数组模拟线段树 进行节点的更新与查询
#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>#define mem(a) memset(a,0,sizeof(a))using namespace std;int a[5005000];int sum;void updat(int id,int l,int r,int mid,int pos){ if(l==r){ a[mid]=pos; return; } int i=(l+r)>>1; if(id<=i)updat(id,l,i,2*mid,pos); else updat(id,i+1,r,2*mid+1,pos); a[mid]=max(a[2*mid],a[2*mid+1]);}void su(int l,int r,int mid,int ll,int rr){ if(l>=ll&&r<=rr){ sum=max(sum,a[mid]); return; } int i=(l+r)>>1; if(ll<=i)su(l,i,2*mid,ll,rr); if(rr>i)su(i+1,r,2*mid+1,ll,rr);}int main(){ int n,m,pos,x1,x2; while(scanf("%d%d",&m,&n)!=EOF){ mem(a); for(int i=1; i<=m; i++){ scanf("%d",&pos); updat(i,1,m,1,pos); } while(n--){ char c[5]; scanf("%s",c);//采用字符串 字符的话要吃回车 if(!strcmp(c,"Q")){ scanf("%d%d",&x1,&x2); sum=0; su(1,m,1,x1,x2); printf("%d\n",sum); } if(!strcmp(c,"U")){ scanf("%d%d",&x1,&x2); updat(x1,1,m,1,x2); } } } 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
- python面向对象的理解
- The 11-th Programming Contest of Hunan University -- Trailing Zeros of Factorials
- hdu-1181-变形课
- 推荐系统——利用上下文信息
- 2015/8/13/Static和final关键字详解
- HDU 1754 I Hate It
- poj 3903
- 动态规划(DP)中LCS问题合集(有待更新中~
- 剑指offer:二进制中1的个数
- what's up
- 苹果开发 笔记(60)文本字体、大小 、颜色、边框 设置
- hdu2122 Ice_cream’s world III(MST)
- 查看当前ubuntu版本号
- 自定义View