Hdu_3308
This question can be done using a line segment tree. The longest lcis in a range is either in the left son, right son, or in the middle.
Single-point update operations are relatively easy to write, because there is no range limit, you only need to update each parent node on the Line Segment tree in sequence.
The query operation has a range limit, but the lcis of the longest range has not changed, that is, it is either in the left son, in the right son, or in the middle. However, due to the range restrictions, we need to discuss the interval classification of different forms when updating the optimal solution.
# Include <stdio. h>
# Include < String . H>
# Define Maxd 100010
Int N, m, a [maxd], MC [ 4 * Maxd], LC [ 4 * Maxd], RC [ 4 * Maxd];
Int Getmax ( Int X, Int Y)
{
Return X> Y? X: Y;
}
Void Update ( Int Cur, Int X, Int Y)
{
Int Mid = (x + y )/ 2 , Ls = 2 * Cur, RS = 2 * Cur + 1 ;
MC [cur] = getmax (MC [ls], MC [RS]);
LC [cur] = Lc [ls], RC [cur] = RC [RS];
If (A [Mid] <A [Mid + 1 ])
{
MC [cur] = getmax (MC [cur], RC [ls] + Lc [RS]);
If (LC [ls] = mid-x + 1 )
LC [cur] + = Lc [RS];
If (RC [RS] = Y-mid)
RC [cur] + = RC [ls];
}
}
Void Build ( Int Cur, Int X, Int Y)
{
Int Mid = (x + y )/ 2 , Ls = 2 * Cur, RS = 2 * Cur +1 ;
If (X = y)
{
MC [cur] = Lc [cur] = RC [cur] = 1 ;
Return ;
}
Build (LS, X, mid );
Build (RS, Mid + 1 , Y );
Update (cur, x, y );
}
Void Init ()
{
Int I, J, K;
For (I = 0 ; I <n; I ++)
Scanf ( " % D " , & A [I]);
Build ( 1 , 0 , N- 1 );
}
Void Refresh ( Int Cur, Int X, Int Y,Int K, Int V)
{
Int Mid = (x + y )/ 2 , Ls = 2 * Cur, RS = 2 * Cur + 1 ;
If (X = y)
{
A [x] = V;
Return ;
}
If (K <= mid)
Refresh (LS, X, mid, K, V );
Else
Refresh (RS, Mid + 1 , Y, K, V );
Update (cur, x, y );
}
Int Query ( Int Cur, Int X, Int Y, Int S, Int T, Int P, Int & ANS)
{
Int Mid = (x + y )/ 2 , Ls = 2 * Cur, RS = 2 * Cur + 1 ;
If (X = y)
Return 1 ;
If (Mid> = T)
Return Query (LS, X, mid, S, T, 0 , ANS );
Else If (Mid + 1 <= S)
Return Query (RS, Mid + 1 , Y, S, T, 1 , ANS );
Else
{
Int Ln, RN;
If (X> = S & Y <= T)
{
Ans = getmax (ANS, MC [cur]);
Return P? RC [cur]: LC [cur];
}
Ln = query (LS, X, mid, S, T, 1 , ANS), Rn = query (RS, Mid + 1 , Y, S, T, 0 , ANS );
If (X> = S & Mid <= T)
{
If (A [Mid] <A [Mid + 1 ])
{
Ans = getmax (ANS, RC [ls] + rn );
If (RC [ls] = mid-x +1 )
Return RC [ls] + rn;
}
Return LC [ls];
}
Else If (Mid + 1 > = S & Y <= T)
{
If (A [Mid] <A [Mid + 1 ])
{
Ans = getmax (ANS, LN + Lc [RS]);
If (LC [RS] = Y-mid)
Return Ln + Lc [RS];
}
Return RC [RS];
}
Else
{
If (A [Mid] <A [Mid + 1 ])
Ans = getmax (ANS, LN + rn );
}
}
Return 0 ;
}
Void Solve ()
{
Int I, J, K, X, Y, ans;
Char B [ 5 ];
For (I = 0 ; I <m; I ++)
{
Scanf ( " % S % d " , B, & X, & Y );
If (B [0 ] = ' Q ' )
{
Ans = 1 ;
Query ( 1 , 0 , N- 1 , X, y, 0 , ANS );
Printf ( " % D \ n " , ANS );
}
Else
Refresh ( 1 , 0 , N- 1 , X, y );
}
}
Int Main ()
{
Int T;
Scanf ( " % D " , & T );
While (T --)
{
Scanf ( " % D " , & N, & M );
Init ();
Solve ();
}
Return 0 ;
}