hdu1754
来源:互联网 发布:笔记本硬盘坏了数据恢复 编辑:程序博客网 时间:2024/06/05 04:12
话说题目不是只有一组数据吗?
这个题目我改了好久,,,,后来发下错在,,查询的时候错了,,,但还是很爽啊。AC。
#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>#include <cstdlib>using namespace std;#define maxn 200005#define inf 0x3f3f3fint a[maxn*8];int b[maxn*4];void build_tree(int node,int l,int r){ int mid=l+(r-l)/2; if(l==r) {a[node]=b[l];return ;} build_tree(node*2,l,mid); build_tree(node*2+1,mid+1,r); a[node]=max(a[node*2],a[node*2+1]); return ;}int x,y;int find_max(int root, int l,int r){ int ans=0x80000000; int mid=l+(r-l)/2; if(x<=l&&y>=r) return a[root];//这里我就是错了。。。留个纪念 if(x<=mid) ans=max(ans,find_max(root*2,l,mid)); if(y>mid) ans=max(ans,find_max(root*2+1,mid+1,r)); return ans;}void update(int root,int l,int r){ int mid=l+(r-l)/2; if(l==r) {a[root]=y; return ;} if(x<=mid) update(root*2,l,mid); else update(root*2+1,mid+1,r); a[root]=max(a[root*2],a[root*2+1]);}int main(){ int n,m; // freopen("in.txt","r",stdin); char t[20]; while(scanf("%d%d",&n,&m)!=EOF) { memset(a,0,sizeof(a)); for(int i=1;i<=n;i++) { scanf("%d",&b[i]); } build_tree(1,1,n); while(m--) { scanf("%s%d%d",&t,&x,&y); if(t[0]=='Q') { if(x>y) { int temp=x; x=y; y=temp; } printf("%d\n",find_max(1,1,n)); } if(t[0]=='U') { update(1,1,n); } } } return 0;}
0 0
- hdu1754
- hdu1754
- hdu1754
- hdu1754
- HDU1754
- hdu1754
- HDU1754
- HDU1754
- hdu1754
- hdu1754
- HDU1754
- hdu1754
- hdu1754
- hdu1754
- hdu1754
- hdu1754
- hdu1754
- HDU1754
- Http网络传递参数中文乱码问题解决办法
- 找出字符串中对称的子字符串的最大长度
- Caffe-图像识别训练
- Java实现排序算法之快速排序
- CSS字体设置
- hdu1754
- java中String字符的替换
- 动态加载与插件化
- Android:view常用属性和操作方法
- Python字符串操作之字符串分割与组合
- uva 10794
- OC循环渐进:开闭原则和里氏替换原则
- linux 内核调试(一)
- 转自“奇谈怪论” 网易博客 事务处理总结:JDBC事务|JTA事务|容器事务