Hdu 3308 LCIs (segment tree)

Source: Internet
Author: User
Tags cas

pid=3308 "target=" _blank "style=" "> topic Links: hdu 3308 LCIs

Topic: Given a sequence, two operations:

    • Q L R: longest continuous increment sequence length in l,r between Sany
    • U p x: Change the number on position p to X

Problem-solving idea: The interval merging on the line tree, which is to infer whether the increment is satisfied when the left and right sub-tree merges.

#include <cstdio>#include <cstring>#include <algorithm>using namespace STD;Const intMAXN =1e5+5;intN, M, A[MAXN];#Define Lson (x) ((x) <<1)#Define Rson (x) (((x) <<1) |intLC[MAXN <<2], RC[MAXN <<2];intL[MAXN <<2], R[MAXN <<2], S[MAXN <<2];voidPushup (intu) {intMID = (Lc[u] + rc[u])/2; S[u] = max (max (S[lson (U), S[rson (U)]), (A[mid] < a[mid+1] ? R[lson (U)] + L[rson (u)]:0)); L[u] = L[lson (u)] + (L[lson (u)] = = Rc[lson (u)]-Lc[lson (u)] +1&& A[mid] < A[mid +1] ?

L[rson (U)]: 0); R[u] = R[rson (u)] + (R[rson (u)] = = Rc[rson (u)]-Lc[rson (u)] + 1 && A[mid] < A[mid + 1]?

R[lson (U)]:0);}voidBuild (intUintLintR) {Lc[u] = l; Rc[u] = r;if(L = = r) {L[u] = R[u] = S[u] =1;return; }intMid = (L + r)/2; Build (Lson (U), L, mid); Build (Rson (U), Mid +1, R); Pushup (u);}voidModify (intUintXintV) {if(Lc[u] = = x && Rc[u] = = x) {A[x] = V;return; }intMID = (Lc[u] + rc[u])/2;if(x <= mid) Modify (Lson (U), X, V);ElseModify (Rson (U), X, V); Pushup (u);}intQuery (intUintLintR) {if(l <= Lc[u] && Rc[u] <= R)returnS[u];intMID = (Lc[u] + rc[u])/2, ret;if(R <= mid) ret = query (Lson (U), L, R);Else if(L > Mid) ret = query (Rson (U), L, R);Else{intll = query (Lson (U), L, R);intrr = Query (Rson (U), L, R);intA = min (R[lson (u)], mid-l +1);intB = min (L[rson (u)], r-mid); RET = max (LL, RR), A[mid] < A[mid +1] ?

A + B:0); }returnRET;}intMain () {intCAsscanf("%d", &cas); while(cas--) {scanf("%d%d", &n, &m); for(inti =0; i < N; i++)scanf("%d", &a[i]); Build1,0, N-1);intL, R;Charop[5]; while(m--) {scanf("%s%d%d", OP, &l, &r);if(op[0] ==' U ') Modify (1, l, R);Else printf("%d\n", Query (1, L, R)); } }return 0;}

Hdu 3308 LCIs (segment tree)

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.