Hdu3308 lcis (simple line segment tree)

Source: Internet
Author: User
Lcis

Time Limit: 6000/2000 MS (Java/others) memory limit: 65536/32768 K (Java/Others)
Total submission (s): 2988 accepted submission (s): 1307


Problem descriptiongiven n integers.
You have two operations:
U a B: Replace the ath number by B. (index counting from 0)
Q a B: output the length of the longest consecutive increasing subsequence (lcis) in [a, B].


Inputt In the first line, indicating the case number.
Each case starts with two integers n, m (0 <n, m <= 105 ).
The next line has n integers (0 <= Val <= 105 ).
The next M lines each has an operation:
U a B (0 <= A, N, 0 <= B = 105)
Or
Q a B (0 <= A <= B <n ).


Outputfor each Q, output the answer.


Sample Input

 
110 107 7 3 3 5 9 9 8 1 8 Q 6 6u 3 4Q 0 1q 0 5q 4 7q 3 5q 0 2q 4 6u 6 10q 0 9


Sample output

 
11423125


Authorsh

A string of numbers. One operation is to change the number A to B. The other is to query the LICs of the range [a, B.

Question Analysis: This is a type of question. You can maintain the Left and Right consecutive values of the endpoint at the same time. For more information, seeCode:

# Include <iostream> # include <cstdio> # include <cstring> using namespace STD; const int n = 100005; struct node {int LC, RC; // range left and right lcis int LV, RV; // range left and right endpoint value int ans; // range lcis} tree [n <2]; int M, N; int max (int A, int B) {return A> B? A: B;} int min (int A, int B) {return A> B? B: A;} void pushup (INT num, int S, int e) {int ls = num <1; int rs = num <1 | 1; int mid = (S + E)> 1; tree [num]. lv = tree [ls]. LV; tree [num]. rv = tree [RS]. RV; tree [num]. lc = tree [ls]. LC; If (tree [ls]. ans = mid-S + 1 & tree [ls]. RV <tree [RS]. LV) tree [num]. lc + = tree [RS]. LC; tree [num]. rc = tree [RS]. RC; If (tree [RS]. ans = e-Mid & tree [RS]. LV> tree [ls]. RV) tree [num]. RC + = tree [ls]. RC; int CMP = max (tree [ls]. RC, tree [RS]. lc); If (tree [ls]. RV <tree [RS]. LV) CMP = tree [ls]. RC + tree [RS]. LC; tree [num]. ans = max (tree [ls]. ANS, max (tree [RS]. ANS, CMP);} void build (INT num, int S, int e) {If (S = e) {scanf ("% d ", & tree [num]. LV); tree [num]. rv = tree [num]. LV; tree [num]. lc = tree [num]. rc = 1; tree [num]. ans = 1; return;} int mid = (S + E)> 1; build (Num <1, S, mid); Build (Num <1 | 1, mid + 1, e); pushup (Num, S, e);} void Update (INT num, int S, int e, int POs, int Val) {If (S = e) {tree [num]. lv = tree [num]. rv = val; return;} int mid = (S + E)> 1; if (Pos <= mid) Update (Num <1, S, mid, POs, val); else Update (Num <1 | 1, Mid + 1, E, POs, Val); pushup (Num, S, e);} int query (INT num, int S, int e, int L, int R) {If (S = L & R = e) {return tree [num]. ans;} int mid = (S + E)> 1; if (r <= mid) return query (Num <1, S, mid, L, R ); else {If (L> mid) return query (Num <1 | 1, Mid + 1, E, L, R ); else {int TA = min (tree [num <1]. RC, mid-L + 1); int TB = min (tree [num <1 | 1]. LC, R-mid); int middle = max (TA, Tb); If (tree [num <1]. RV <tree [num <1 | 1]. LV) Middle = Ta + Tb; return max (query (Num <1, S, mid, L, mid), max (query (Num <1 | 1, mid + 1, E, Mid + 1, R), middle) ;}} int main () {int t; char op [3]; int A, B; scanf ("% d", & T); While (t --) {scanf ("% d", & N, & M); Build (1, 1, n ); while (M --) {scanf ("% s", OP); scanf ("% d", & A, & B ); if (OP [0] = 'q') printf ("% d \ n", query (1, 1, n, A + 1, B + 1 )); else Update (, N, A + 1, B) ;}} return 0 ;}// 343ms5376k

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.