HDU 1754 I Hate It 线段树入门
来源:互联网 发布:js urlencode转码 编辑:程序博客网 时间:2024/05/02 04:58
//读取字符的时候要用字符数组 单个字符会WA#include<stdio.h>#include<string>#include<cstring>#include<queue>#include<algorithm>#include<functional>#include<vector>#include<iomanip>#include<math.h>#include<iostream>#include<sstream>#include<set>#include<climits>#include<map>#include<bitset>using namespace std;const int MAX=200005;int A[MAX],F[4*MAX];void build(int x,int left,int right){ if (left==right) { F[x]=A[left]; return; } int mid=(left+right)/2; build(x*2,left,mid); build(x*2+1,mid+1,right); F[x]=max(F[x*2],F[x*2+1]);}void change(int x,int left,int right,int pos,int num){ if (left==right) { F[x]=num; return; } int mid=(left+right)/2; if (pos<=mid) change(x*2,left,mid,pos,num); else change(x*2+1,mid+1,right,pos,num); F[x]=max(F[x*2],F[x*2+1]);}int query(int x,int left,int right,int L,int R){ if (left>=L&&right<=R) return F[x]; if (right<L||left>R) return -99999999; if (left==right) return F[x]; int mid=(left+right)/2; if (R<=mid) return query(x*2,left,mid,L,R); else if (L>mid) return query(x*2+1,mid+1,right,L,R); else return max(query(x*2,left,mid,L,R),query(x*2+1,mid+1,right,L,R));}int main(){ int N,M,a,b; char command[15]={0}; while (scanf("%d%d",&N,&M)!=EOF) { for (int i=1;i<=N;i++) scanf("%d",&A[i]); build(1,1,N); for (int i=1;i<=M;i++) { scanf("%s %d%d",command,&a,&b); if (command[0]=='Q') printf("%d\n",query(1,1,N,a,b)); else if (command[0]=='U') change(1,1,N,a,b); } } return 0;}
0 0
- 【hdu】【线段树入门】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 [线段树]
- vs2010下release版本调试设置
- React 入门实例教程
- CodeForces 635C XOR Equation 数学 公式
- 自定义set比较函数
- POJ 1265 pick公式
- HDU 1754 I Hate It 线段树入门
- Ele SOA Container
- 自定义View,绘制自己的手表Demo
- python request属性及方法说明
- 基本类型变量和类型变量+基础
- 8-15比赛总结
- HDU 1698 Just a Hook 线段树 区间更新 惰性标记
- 一看就懂的ReactJs入门教程(精华版)
- CodeForces 706D Vasiliy's Multiset 字典树