1#include <iostream>2#include <string>3#include <algorithm>4#include <cstdlib>5#include <cstdio>6#include <Set>7#include <map>8#include <vector>9#include <cstring>Ten#include <stack> One#include <cmath> A#include <queue> -#include <bits/stdc++.h> - using namespacestd; the - intmax[4000001]; - //int max (int a,int b) - //{ + //return a>b?a:b; - //} + voidPushup (intRT) A { atMax[rt]=max (max[rt<<1],max[(rt<<1)+1]); - } - voidBuildintLintRintRT) - { - if(l==R) - { inscanf"%d",&Max[rt]); - return; to } + intM= (l+r) >>1; -Build (l,m,rt<<1); theBuild (m+1, R, (rt<<1)+1); * pushup (RT); $ }Panax Notoginseng voidUpdateintPintQintLintRintRT) - { the if(l==R) + { Amax[rt]=Q; the return; + } - intM= (l+r) >>1; $ if(p<=m) $Update (p,q,l,m,rt<<1); - Else -Update (p,q,m+1, R, (rt<<1)+1); the pushup (RT); - }Wuyi intGetmax (intLintRintLintRintRT) the { - if(l<=l&&r<=R) Wu returnMax[rt]; - intM= (r+l) >>1; About intret=0; $ if(l<=m) -Ret=max (Ret,getmax (l,r,l,m,rt<<1)); - if(r>m) -Ret=max (Ret,getmax (l,r,m+1, R, (rt<<1)+1)); A returnret; + } the intMain () - { $ intn,m,a,b,i; the CharC; the while(~SCANF ("%d%d",&n,&m)) the { theBuild1N1); - for(i=0; i<m; i++) in { thescanf"%*c%c%d%d", &c,&a,&b);//*c is the same as GetChar . the if(c=='Q') Aboutprintf"%d\n", Getmax (A, B,1N1)); the Else theUpdate (A, B,1N1); the } + } - return 0; the}
View Code
HDU 1754 I Hate It segment Tree single point update interval maximum