hdu 1754 I Hate It
来源:互联网 发布:网络博物馆 编辑:程序博客网 时间:2024/06/01 09:37
线段树的单点更新
详情请见代码:
#include<stdio.h>#include<stdlib.h>#include<string.h>#include<iostream>#include<algorithm>#define maxn 200100using namespace std;int sto[maxn<<2];int up[maxn<<2];void Insert(int left,int right,int o){ up[o]=0; if(left==right) { scanf("%d",&sto[o]); return ; } int lso=o<<1; int mid=(left+right)>>1; Insert(left,mid,lso); Insert(mid+1,right,lso|1); sto[o]=max(sto[lso],sto[lso|1]);}void changedata(int o){ if(up[0]!=0) { int lso=o<<1; up[lso]=up[o]; up[lso|1]=up[o]; sto[lso]=up[o]; sto[lso|1]=up[o]; up[o]=0; }}int getdata(int left,int right,int o,int begin,int end,int val){ if(begin<=left&&right<=end) { if(val!=1<<28) { up[o]=val; sto[o]=val; } return sto[o]; } changedata(o); int lso=o<<1; int mid=(right+left)>>1; int ans=-1<<10; if(begin<=mid)ans=max(ans,getdata(left,mid,lso,begin,end,val)); if(mid<end)ans=max(ans,getdata(mid+1,right,lso|1,begin,end,val)); sto[o]=max(sto[lso],sto[lso|1]); return ans;}int main(){ int m,n; while(~scanf("%d%d",&n,&m)) { Insert(1,n,1); char str[5]; int x,y; for(int i=0;i<m;i++) { scanf("%s",str); if(str[0]=='Q') { scanf("%d%d",&x,&y); printf("%d\n",getdata(1,n,1,x,y,1<<28)); } if(str[0]=='U') { scanf("%d%d",&x,&y); int z=getdata(1,n,1,x,x,y); } } } 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
- 线程局部存储技术
- iOS调试常见错误 如:symbol(s) not found for architecture x86_64
- 7_4_F题 Task 题解[hdu 4846](贪心)
- Android常用ADB命令
- iOS开发拓展篇——如何把项目托管到GitHub
- hdu 1754 I Hate It
- 手机端多行文本结尾省略号方法
- 利用函数的作用域来封装
- android工具的使用
- windbg调试应用层程序
- android adb push apk&jar重启机子无效
- rpm 按时间排序查询列出名称,版本,发布号,架构,时间
- WebSocket编程-sunliggggg
- wait_queue_head_t和wait_queue_t