HDU 5316 Magician Segment Tree

Source: Internet
Author: User

Links: http://acm.hdu.edu.cn/showproblem.php?pid=5316

MagicianTime limit:18000/9000 MS (java/others) Memory limit:65536/65536 K (java/others)
Total submission (s): Accepted submission (s): 54


Problem Descriptionfantasy magicians usually gain their ability through one of the three usual methods:possessing it as an in Nate Talent, gaining it through study and practice, or receiving it from another being, often a god, spirit, or demon of s ome sort. Some Wizards is depicted as have a special gift which sets them apart from the vast majority of characters in fantasy W Orlds who is unable to learn magic.

Magicians, sorcerers, wizards, Magi, and practitioners of magic by other titles has appeared in myths, folktales, and lit Erature throughout recorded, with fantasy works drawing from this background.

In medieval chivalric romance, the wizard often appears as a wise old man and acts as a mentor, with Merlin from the King Arthur stories representing a prime example. Other magicians can appear as villains, hostile to the hero.



Mr Zstu is a magician, he had many elves like Dobby, and each of the which has a magic power (maybe negative). One day, Mr. Zstu want to test his ability of doing some magic. He made the Elves stand in a straight line, from position 1 to position n, and he used both kinds of magic, change magic an D Query Magic, the first is to change an elf's power, the second is get the maximum sum of beautiful subsequence of a give N interval. A beautiful subsequence is a subsequence then all the adjacent pairs of elves in the sequence has a different parity of P Osition. Can do the same thing as Mr Zstu?


Inputthe first line was an integer T represent the number of test cases.
Each of the test case begins with a integers n, m represent the number of elves and the number of the time that Mr. Zstu use D his magic.
(N,m <= 100000)
The next line have n integers represent elves ' magic power, magic Power is between-1000000000 and 1000000000.
followed M lines, each of the line have three integers like
Type a B describe a magic.
If type equals 0, you should output the maximum sum of beautiful subsequence of interval [a, b]. (1 <= a <= b <= N)
If type equals 1, you should the magic power of the elf in position A to B. (1 <= a <= n, 1 <= b <= 1e9)

Outputfor each 0 type query, output the corresponding answer.
Sample Input
11 110 1 1

Sample Output
1



Test instructions: There are n numbers, two operations, 0 operations, output L to R, all odd and even alternating sub-sequences, the maximum and value of the values. (The self-sequence can be used without continuous). 1 The operation is to change the number of a position to B.


Practice: maintenance intervals within the

Jiou, this interval begins with an odd digit, the maximum and the number of all sub-sequences ending with an even digit.

Ouji,jiji,ouou three numbers in the same vein.








#include <cstdio> #include <algorithm> #include <stdio.h> #include <string.h>using namespace Std #define Lson L, M, RT << 1#define Rson m + 1, R, RT << 1 | 1#define LL __int64#define inf-100000000000000000const int maxn = 111111;struct point {__int64 Jiji,ouou,jiou,ouji;} ;p oint pp[maxn<<2];    int jiou[maxn<<2];p oint big (point A,point b) {point C;    C.jiji=max (A.jiji,b.jiji);    C.jiji=max (C.jiji,a.jiji+b.ouji);    C.jiji=max (C.jiji,a.jiou+b.jiji);    C.jiji=max (C.jiji,inf);    C.jiou=max (A.jiou,b.jiou);    C.jiou=max (C.jiou,a.jiji+b.ouou);    C.jiou=max (C.jiou,a.jiou+b.jiou);    C.jiou=max (C.jiou,inf);    C.ouji=max (A.ouji,b.ouji);    C.ouji=max (C.ouji,a.ouji+b.ouji);    C.ouji=max (C.ouji,a.ouou+b.jiji);    C.ouji=max (C.ouji,inf);    C.ouou=max (A.ouou,b.ouou);    C.ouou=max (C.ouou,a.ouji+b.ouou);    C.ouou=max (C.ouou,a.ouou+b.jiou);    C.ouou=max (C.ouou,inf); return c;} void pushup (int rt) {Pp[rt]=big (pp[rt<<1],pp[rt&Lt;<1|1]);}            int kk=1;void Build (int l,int R,int RT) {if (L = = r) {if (kk&1) {jiou[rt]=1;            scanf ("%i64d", &pp[rt].jiji);            Pp[rt].ouou=inf;            Pp[rt].ouji=inf;        Pp[rt].jiou=inf;            } else {jiou[rt]=0;            scanf ("%i64d", &pp[rt].ouou);        Pp[rt].jiou=pp[rt].jiji=pp[rt].ouji=inf;        } kk++;    return;    } int m = (L + r) >> 1;    Build (Lson);    Build (Rson); Pushup (RT);} void update (int l,int c,int l,int r,int RT) {if (l==r&&l==l) {if (jiou[rt]==1) pp[rt].jiji=        C        if (jiou[rt]==0) pp[rt].ouou=c;    return;    } int m = (L + r) >> 1;    if (l <= m) update (L, C, Lson);    else update (L, C, Rson); Pushup (RT);}    Point query (int l,int r,int l,int r,int RT) {if (L <= l && R <= R) {return PP[RT];    } int m = (L + r) >> 1; if (l<=M&AMP;&AMP;M&LT;R) return big (query (L, R, Lson), query (L, R, Rson));    if (l<=m) return query (L, R, Lson);      if (m<r) return query (L, R, Rson);    }int Main () {int t;    int n,q;    scanf ("%d", &t);        while (t--) {scanf ("%d%d", &n,&q);        kk=1;        if (n) build (1, N, 1);             while (q--) {int op;            int A, B;            scanf ("%d", &op);            scanf ("%d%d", &a,&b);                 if (n==0) {if (op==0) puts ("0");            Continue                } if (op==0) {if (a>b) swap (A, b);                Point Ppp=query (a,b,1,n,1);            printf ("%i64d\n", Max (Ppp.jiji,max (Ppp.jiou,max (Ppp.ouji,ppp.ouou)));        } else update (A, B, 1, n, 1); }} return 0;}




Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

HDU 5316 Magician 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.