The line tree solves, similarly, the array of numbers is OK.
Point modification, the interval query is the complexity of LOGN.
There is no use of the bottom-up zkw line segment tree notation, the normal recursive line segment tree.
#include <cstdio> #include <cstring> #include <string> #include <queue> #include <algorithm > #include <map> #include <stack> #include <iostream> #include <list> #include <set># include<bitset> #include <vector> #include <cmath> #define INF 0x7fffffff#define EPS 1e-8#define LL Long Long#define PI 3.141592654#define CLR (A, B) memset (A,b,sizeof (a)) #define for (I,A,B) for (int i=a;i<b;i++) #define For_ (I,A,B) for (int i=a;i>=b;i--) #define PUB push_back#define PUF push_front#define pob pop_back#define pof pop_front #define MP make_pair#define ft first#define SD second#define SF scanf#define PF printf#define sz (v) ((int) (v). Size ()) #defi NE All (v) (v). Begin (), (v). End () #define ACFUN Std::ios::sync_with_stdio (false) #define SIZE 400000 +1#define MOD 1000000007using namespace Std;int a[size];int _max[size];int n,m;int Build (int o,int l,int R) {if (l==r) return _max[o]=a [L]; int m= (L+R) >>1; Return _max[o]=max (Build (O*2,l,m), Build (o*2+1,m+1,r));} int ql,qr;int query (int o,int l,int R) {if (ql<=l&&qr>=r) return _max[o]; int m= (L+R) >>1; int ans=-inf; if (ql<=m) Ans=max (Ans,query (o*2,l,m)); if (qr>m) Ans=max (Ans,query (o*2+1,m+1,r)); return ans;} int site,up;void update (int o,int l,int R) {if (l==r) _max[o]=up; else {int m= (L+R) >>1; if (site<=m) update (O*2,L,M); else update (O*2+1,M+1,R); _max[o]=max (_max[o*2],_max[o*2+1]); }}int Main () {while (~SF ("%d%d", &n,&m)) {CLR (_max,0); for (i,1,n+1) SF ("%d", &a[i]); Build (1,1,n); char c; while (m--) {GetChar (); SF ("%c", &c); if (c== ' Q ') {SF ("%d%d", &QL,&QR); PF ("%d\n", Query (1,1,n)); } else if (c== ' U ') {SF ("%d%d", &site,&up); Update (1,1,N); } } }}
HDU 1754 I Hate It