In the first row of each test, there are two positive integers N and M (0 <N <= 200000,0 <M <5000), representing the number of students and the number of operations respectively. Student ID numbers are separated from 1 to N. The second row contains N integers, indicating the initial score of the N students. The number of I represents the score of the students whose ID is I. Next there are M rows. Each line has A character C (only 'q' or 'U'), and two positive integers A and B. When C is 'Q', it indicates that this is A query operation. It asks the students whose ID ranges from A to B (including A and B) about the highest score. When C is 'U', it indicates that this is an update operation. You must change the score of students whose ID is A to B. --> Modified the line segment tree. Fortunately, this recursive build has not timed out, and it has been 437MS! [Cpp] # include <cstdio> # include <algorithm> using namespace std; const int maxn = 200000 + 10, INF =-214748364; int a [maxn], maxv [4 * maxn], A, B; // a is the input array, maxv is the array of Line Segment Tree nodes, and the maximum value void update (int o, int L, int R) // line segment tree update. Change a [A] To B {if (L = R) maxv [o] = B; else {int M = L + (R-L)/2; if (A <= M) update (2 * o, L, M ); else update (2 * o + 1, M + 1, R); maxv [o] = max (maxv [2 * o], maxv [2 * o + 1]) ;}} int query (in T o, int L, int R) // query the maximum value between [A, B] In A line segment tree {if (A <= L & R <= B) return maxv [o]; int M = L + (R-L)/2, ans = INF; if (A <= M) ans = max (ans, query (2 * o, L, M); if (B> M) ans = max (ans, query (2 * o + 1, M + 1, R )); return ans;} void build (int o, int L, int R) // build {if (L = R) {maxv [o] = a [L]; return;} int M = L + (R-L)/2; if (L <= M) build (2 * o, L, M); if (R> M) build (2 * o + 1, M + 1, R); maxv [o] = max (ma Xv [2 * o], maxv [2 * o + 1]);} www.2cto. comint main () {int N, M; char C; while (~ Scanf ("% d \ n", & N, & M) {for (int I = 1; I <= N; I ++) scanf ("% d", & a [I]); build (1, 1, N); while (M --) {scanf ("\ n % c % d", & C, & A, & B); if (C = 'U') update (1, 1, n); else printf ("% d \ n", query (1, 1, N) ;}} return 0 ;}