hdu1754I Hate It
2016-04-14 19:31
323 查看
链接: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 ,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; }
相关文章推荐
- centos下configure zeromq-4.1.2时错误解决方法
- 管理软件的欺骗式营销
- Instant Run
- 操作系统开发系列—9.Loader
- 染色
- 老戚的黑科技之SSH隧道技术
- markdown(二)语法
- 5.1 抽象化
- tomcat单机多实例部署
- 递归
- oracle中实现截取字符串(substr)、查找字符串位置(instr)、替换字符串(replace)
- ActiveX(MFC)控件——添加接口及WEB调用
- JAVA集合类图
- 基于稀疏三维变换域协同滤波的图像降噪
- 利用中间件Multer实现上传功能
- Listview中嵌套ImageView,ImageView高度自适应时,显示不占满布局有空白,解决方案
- Android 5.0 Notification的改变
- struts1 action 之间的跳转
- 最长公共子序列
- 细说exports和module.exports