Hdu 1754——I Hate It
来源:互联网 发布:砸金蛋抽奖软件 编辑:程序博客网 时间:2024/06/05 16:57
线段树
单点更新
#include<cstdio>#include<iostream>using namespace std;struct Node{int left;int right;int max;}node[200000*4];int Max(int a,int b){return a>b?a:b;}void TreeMake(int l,int r,int i){node[i].left=l;node[i].right=r;node[i].max=0;if(l==r)return ;int m=(l+r)>>1;TreeMake(l,m,i<<1);TreeMake(m+1,r,i<<1|1);}void TreeUpdate(int x,int s,int i){int l=node[i].left;int r=node[i].right;int m=(l+r)>>1;if(l==x&&r==x){node[i].max=s;return ;}if(node[i].max<s){node[i].max=s;}if(x<=m)TreeUpdate(x,s,i<<1);elseTreeUpdate(x,s,i<<1|1);}int TreeQuery(int x,int y,int i){int l=node[i].left;int r=node[i].right;int m=(l+r)>>1;int ans=0;if(x==l&&y==r)return node[i].max;if(y<=m){ans=TreeQuery(x,y,i<<1);}else{if(x>m)ans=TreeQuery(x,y,i<<1|1);elseans=Max(TreeQuery(x,m,i<<1),TreeQuery(m+1,y,i<<1|1));}return ans;}int main(){int n,m;while(~scanf("%d%d",&n,&m)){TreeMake(1,n,1);int temp;for(int i=1;i<=n;i++){scanf("%d",&temp);TreeUpdate(i,temp,1);}char ch;int x,y;for(int i=0;i<m;i++){getchar();scanf("%c %d %d",&ch,&x,&y);if(ch=='Q'){printf("%d\n",TreeQuery(x,y,1));}else{TreeUpdate(x,y,1);}}}return 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
- 进程关系之进程组、会话和控制终端
- matlab练习程序(SUSAN检测)
- python列表排序
- Serializable初次学习
- 关于精度宽度设置
- Hdu 1754——I Hate It
- python os模块,平常操作文件方便,执行cmd命令
- 求1-N内的素数
- xcode: valid signing identity not found
- linux chmod命令
- 黑马程序员——反射机制
- 面向对象(购买电脑)
- windows + visual studio 2010 配置SVN
- CListCtrl 使用技巧