Title Link: http://acm.hdu.edu.cn/showproblem.php?pid=5316
Test Instructions: give you n points, m operations, each operation has 3 integers t,a,b,t represents the operation type, when t=1 the value of a point is changed to B; When T=0, the largest sub-sequence between the query interval a, B, and the original subscript parity of the adjacent elements in this subsequence are different.
Ideas: the difficulty of this problem is in the query, the rest are templates, and according to the query, you just have to compare the next interval of the odd and even the largest case, merge into the previous interval so that you can build a interval of each node in the odd opening even the beginning of the odd end, even the end of these interval conditions of the tree.
Code:
#include <cstdio> #include <cstdlib> #include <cmath> #include <iostream > #include <algorithm> #include <vector> #define N 100005#define LL __int64#define inf 0x3f3f3f3fusing namespace std; #define ls rt<<1#define rs rt<<1|1#define lson l,m,rt<<1#define rson m+1,r,rt<<1| 1struct node{int l,r; LL&NBSP;JO,OO,OJ,JJ;} seg[n<<4],aa; Ll ans;void push_up (INT&NBSP;RT) { seg[rt].jj=max (max (Seg[ls].jj+seg[rs].oj, SEG[LS].JO+SEG[RS].JJ), Max (SEG[LS].JJ,SEG[RS].JJ)); seg[rt].oo=max (Max (seg[ls].oo+seg[ rs].jo,seg[ls].oj+seg[rs].oo), Max (seg[ls].oo,seg[rs].oo)); seg[rt].jo=max (Max (SEG[LS). Jj+seg[rs].oo,seg[ls].jo+seg[rs].jo), Max (Seg[ls].jo,seg[rs].jo)); seg[rt].oj=max (Max ( SEG[LS].OO+SEG[RS].JJ,SEG[LS].OJ+SEG[RS].OJ), Max (seg[ls].oj,sEg[rs].oj));} Void build (INT&NBSP;L,INT&NBSP;R,INT&NBSP;RT) { seg[rt].l=l; seg[rt].r=r; if (l==r) { &NBSP;&NBSP;&NBSP;LL&NBSP;A;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;SCANF ("%I64d", &a); if (l&1) { seg[rt].jj=a; seg[rt].oo=-INF; } else { seg[rt].oo=a; seg[rt].jj=-INF; } seg[rt].jo=seg[rt].oj=-inf; return ; } int m= (l+r) >>1; build (Lson) ; build (Rson); push_up (RT);} Void update (INT&NBSP;P,INT&NBSP;X,INT&NBSP;RT) { if (seg[rt].l==seg[rt].r&& seg[rt].l==p) { if (p&1) seg[rt].jj=x; else seg[rt].oo=x; return ; } int m= (SEG[RT].L+SEG[RT].R) >>1; if (p<=m) update (P,X,LS); else update (P,x,rs); push_up (RT);} Void get (NODE&NBSP;LL,NODE&NBSP;RR) { aa.jj=max (max (LL.JJ+RR.OJ,LL.JO+RR.JJ), Max ( LL.JJ,RR.JJ)); aa.oo=max (Max (ll.oo+rr.jo,ll.oj+rr.oo), Max (ll.oo,rr.oo)); aa.jo=max (Max (Ll.jj+rr.oo,ll.jo+rr.jo), Max (Ll.jo,rr.jo)); aa.oj=max (Max ( LL.OO+RR.JJ,LL.OJ+RR.OJ), Max (Ll.oj,rr.oj));} Node query (INT&NBSP;L,INT&NBSP;R,INT&NBSP;RT) { if (seg[rt].l==l&&seg[rt].r= =R) { aa=seg[rt]; ans=max (Max (Aa.jj,aa.jo), Max (aa.oj,aa.oo)); return seg[rt]; } int m= (Seg[rt].l+seg[rt] . R) >>1; ans=0; if (r<=m) &nbsP; aa=query (L,r,ls); else if (l>m) aa=query (L,R,RS); else { node ll,rr; ll= Query (Lson); rr=query (Rson); get (LL,RR); } ans=max (Max (Aa.jj,aa.jo), Max ( aa.oj,aa.oo)); return aa;} Int main () { int n,m,a,b,t,t;while (scanf ("%d", &t) ==1) { while (t--) { &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;SCANF ("%d%d", &n,&m); build (1,n,1); &nBsp; while (m--) { &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;SCANF ("%d%d%d",& T,&A,&B); if (t==1) update (a,b,1); else { query (a,b,1); printf ("%i64d\n", ans); } } }}return 0;}
This article is from the "Acfun" blog, make sure to keep this source http://9712315.blog.51cto.com/9702315/1679702
HDU 5316 Magician (the 1th problem of the third field of 2015 schools) segment tree single point update + interval merge