//1A b change the number of a position to b//0A b output [b] maximum sum of beautiful subsequence//a beautiful subsequence is a subsequence so all the adjacent pair S//of ElvesinchThe sequence has a different parity of position//maintenance Oto, OTE, ete, and Eto represent the largest beautiful subsequence of the parity case of this interval starting and ending points respectively#include <iostream>#include <set>#include <map>#include <algorithm>#include <cmath>#include <vector>#include <queue>#include <string>Using namespaceSTD;#define MAXN 100100#define Lson l,m,rt<<1#define Rson m+1,r,rt<<1|1#define LEFT Rt<<1#define RIGHT Rt<<1|1#define INF 0x3f3f3f3f3f3f3fstruct node{Long Long ote,oto,ete,eto;int TT;};Node t[maxn*8];void pushup (int rt) {int ls=rt<<1,ls2=rt<<1|1;T[RT]. OTE=max (T[ls]. OTE+T[LS2]. OTE, T[ls]. Oto+T[LS2]. Ete);T[RT]. OTE=max (Max (T[RT). OTE, T[ls]. OTE), T[LS2]. OTE);T[RT]. Oto=max (T[ls]. Oto+T[LS2]. Eto, T[ls]. OTE+T[LS2]. Oto);T[RT]. Oto=max (Max (T[RT). Oto, T[ls]. Oto), T[LS2]. Oto);T[RT]. Eto=max (T[ls]. Eto+T[LS2]. Eto, T[ls]. Ete+T[LS2]. Oto);T[RT]. Eto=max (Max (T[RT). Eto, T[ls]. Eto), T[LS2]. Eto);T[RT]. Ete=max (T[ls]. Ete+T[LS2]. OTE, T[ls]. Eto+T[LS2]. Ete);T[RT]. Ete=max (Max (T[RT). Ete, T[ls]. Ete), T[LS2]. Ete);Return;}int tot;void CSH (int rt) {T[RT]. Ete=-INF,T[RT]. Eto=-INF,T[RT]. OTE=-INF,T[RT]. Oto=-inf;Return;}void Build (int l,int r, int rt) {if (l==r) {Long longx;Cin>>x;tot++;CSH (RT);T[RT]. TT=tot;if (tot%2) T[rt]. Oto=x;else T[rt]. Ete=x;Return;} int m= (L+R) >>1;Build (Lson);Build (Rson);CSH (RT);Pushup (RT);Return;}void Update (int p,long long cha,int l,int r,int RT) {if (l==r) {if (T[rt]. TT%2) T[rt]. Oto=cha;else T[rt]. Ete=cha;Return;} int m= (L+R) >>1;if (p<=m) update (P,cha,lson);else Update (P,cha,rson);Pushup (RT);}node HB (node A,node b) {node ans;Ans. Ete=max (Max (Max (a. Eto+b. EteA. Ete+b. OTE), a. Ete), b. Ete);Ans. Eto=max (Max (Max (a. Ete+b. OtoA. Eto+b. Eto), a. Eto), b. Eto);Ans. OTE=max (Max (Max (a. OTE+b. OTEA. Oto+b. Ete), a. OTE), b. OTE);Ans. Oto=max (Max (Max (a. Oto+b. EtoA. OTE+b. Oto), a. Oto), b. Oto);return ans;}node query (int l,int r,int l,int r,int RT) {if (l<=l && r>=r) return T[RT];int m= (L+R) >>1;Node A, b;A. Ete=a. Eto=a. OTE=a. Oto=-inf;B. Ete=b. Eto=b. OTE=b. Oto=-inf;if (l<=m) a=query (L,r,lson);if (r>m) b=query (L,r,rson);Return HB (A, B);}int Main () {//freopen ("In.txt","R", stdin);Ios_base::sync_with_stdio (0);int CAs;Cin>>cas;while (cas--) {tot=0;int N,m;Cin>>n>>m;Build1N1);while (m--) {Long longx, A, B;Cin>>x>>a>>b;Ifx) Update (A, B,1N1);else{node Ans=query (A, B,1N1);Long Long answer=-inf;Answer=max (max (ans. Ete, ans. Eto), Max (ans. OTE, ans. Oto));Cout<<answer<<endl;}}} return0;}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Hdu5316magician segment Tree