hdu1754I Hate It
来源:互联网 发布:局域网共享端口开启 编辑:程序博客网 时间:2024/06/04 18:51
链接:http://acm.hdu.edu.cn/showproblem.php?pid=1754
题意:中文题。
分析:线段树练习题。单点更新,区间查询最大值。(那些跑得快的应该是写的zkw线段树吧。)
代码:
#include<map>#include<set>#include<cmath>#include<queue>#include<bitset>#include<math.h>#include<cstdio>#include<vector>#include<string>#include<cstring>#include<iostream>#include<algorithm>#pragma comment(linker, "/STACK:102400000,102400000")using namespace std;const int N=200100;const int MAX=1000000100;const int mod=100000000;const int MOD1=1000000007;const int MOD2=1000000009;const double EPS=0.00000001;typedef long long ll;const ll MOD=998244353;const ll INF=10000000010;typedef double db;typedef unsigned long long ull;char s[3];int a[N],mx[4*N];void build(int x,int l,int r) { if (l==r) { mx[x]=a[l];return ; } int mid=(l+r)>>1; build(2*x,l,mid); build(2*x+1,mid+1,r); mx[x]=max(mx[2*x],mx[2*x+1]);}int query(int x,int l,int r,int L,int R) { if (l==L&&r==R) return mx[x]; int mid=(l+r)>>1; if (R<=mid) return query(2*x,l,mid,L,R); else if (L>mid) return query(2*x+1,mid+1,r,L,R); else return max(query(2*x,l,mid,L,mid),query(2*x+1,mid+1,r,mid+1,R));}void updata(int x,int l,int r,int y,int z) { if (l==r) { mx[x]=z;return ; } int mid=(l+r)>>1; if (y<=mid) updata(2*x,l,mid,y,z); else updata(2*x+1,mid+1,r,y,z); mx[x]=max(mx[2*x],mx[2*x+1]);}int main(){ int i,n,m,l,r; while (scanf("%d%d", &n, &m)!=EOF) { for (i=1;i<=n;i++) scanf("%d", &a[i]); build(1,1,n); while (m--) { scanf("%s%d%d", s, &l, &r); if (s[0]=='Q') printf("%d\n", query(1,1,n,l,r)); else updata(1,1,n,l,r); } } return 0;}
0 0
- hdu1754I Hate It
- hdu1754I Hate It
- hdu1754I Hate It
- 线段树-HDU1754I Hate It
- hdu1754I Hate It(线段树)
- 线段树之HDU1754I Hate It
- hdu1754I Hate It(线段树---单点更新,区间求值)
- I Hate It
- hdu1754 I Hate It
- HDU1754 I Hate It
- BIT1083 I Hate It
- HDU1754:I Hate It
- HDU1754--I Hate It
- HDU1754 I hate it
- I Hate It tzc
- hdu_1754 I Hate It
- hdu1754 I Hate It
- HDU1754:I Hate It
- JAVA集合类图
- 基于稀疏三维变换域协同滤波的图像降噪
- centos下configure zeromq-4.1.2时错误解决方法
- 64位UBUNTU 下安装和配置使用python的spark
- 利用中间件Multer实现上传功能
- hdu1754I Hate It
- 2016年腾讯产品笔试真题
- 5.1 抽象化
- markdown(二)语法
- ubuntu14.04 安装 搜狗输入法
- 老戚的黑科技之SSH隧道技术
- 管理软件的欺骗式营销
- 染色
- Android编程之内存溢出解决方案(OOM)实例总结