To query the maximum value of a certain range of a series, data is updated.
Such a question can use a tree array, but it is better to use a line segment tree because interval operations are involved.
However, it is also possible to use a tree array, that is, the query is troublesome. Pay attention to the calculation and do not exceed the range.
Looking at the query function below, this is the main difficult function. Among them, the-1 operation and the judgment r-lowbit (r)> = l are all very painful, an error occurs when you are not careful.
# Include
# Include using namespace std; class IHateIt_1754_2 {static const int SIZE = 200002; int * a, * c; // a is a normal array, c is the tree array inline int lowbit (int x) {return x & (-x);} void update (int I, int val, int len) {a [I] = val; while (I <= len) {c [I] = max (c [I], val ); I + = lowbit (I) ;}} int query (int l, int r) {int ans = a [r]; // upper boundary while (l! = R) {for (r-= 1; r-lowbit (r)> = l; r-= lowbit (r) {ans = max (ans, c [r]); // pay attention to the calculation interval, do not boast range} ans = max (ans, a [r]); // bottom boundary} return ans;} public: IHateIt_1754_2 (): a (int *) malloc (sizeof (int) * SIZE), c (int *) malloc (sizeof (int) * SIZE )) {int N, M; while (scanf ("% d", & N, & M )! = EOF) {fill (c, c + N + 1, 0); for (int I = 1; I <= N; I ++) {scanf ("% d", & a [I]); update (I, a [I], N) ;}while (M --) {char op [2]; int a, B; scanf ("% s % d", op, & a, & B); if (op [0] = 'U ') update (a, B, N); else printf ("% d \ n", query (a, B ));}}}~ IHateIt_1754_2 () {free (a), free (c );}};