HDU 1754 I Hate It
来源:互联网 发布:vivox7系统优化的如何 编辑:程序博客网 时间:2024/06/01 10:35
线段树入门
#include<stdio.h>#include<string.h>#include<algorithm>#define lson rt<<1#define rson (rt<<1)+1using namespace std;int a[1000001];char b[1000001];void build(int l,int r,int rt){ if(l==r) { scanf("%d",&a[rt]); return; } int mid=(l+r)>>1; build(l,mid,lson); build(mid+1,r,rson); a[rt]=max(a[lson],a[rson]);}void update(int l,int r,int rt,int pos,int value){ if(l==r) { a[rt]=value; return; } int mid=(l+r)/2; if(pos<=mid) update(l,mid,lson,pos,value); else update(mid+1,r,rson,pos,value); a[rt]=max(a[lson],a[rson]);}int query(int l,int r,int rt,int L,int R){ int ma=0; if(L<=l&&r<=R) { ma=max(a[lson],a[rson]); return a[rt]; } int mid=(l+r)>>1; if(L<=mid) ma=max(ma,query(l,mid,lson,L,R)); if(R>mid) ma=max(ma,query(mid+1,r,rson,L,R)); return ma;}int main(){ int i,j,k,n,m,l,x,y; while(~scanf("%d %d",&n,&m)) { build(1,n,1); //printf("(%d)\n",a[2]); for(i=0;i<m;i++) { scanf("%s %d %d",b,&x,&y); if(b[0]=='Q') { printf("%d\n",query(1,n,1,x,y)); } else if(b[0]=='U') { // printf("(1)"); update(1,n,1,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
- 第k短路径的学习,及A*算法的初步认识,以及usaco牛跑步,k短路径
- HTML框架
- 深入浅出ES6(十三):类 Class
- IPv6 地址
- jQuery 实现Ajax
- HDU 1754 I Hate It
- Caffe 深度学习框架上手教程
- spring多种格式日期类型绑定
- POJ 2773 Happy 2006(容斥原理+二分)
- mysql主从复制跳过错误
- 【JS】IP大小端转换&十进制数字转换成IP
- Luo 1233 工作分配
- HTML DOM Event 对象
- button圆角