1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174
|
import java.io.*; import java.util.*;
public class Main { final static long inf=0x4000000000000000L; final static int maxn=100010; static int[] a=new int[maxn+1]; static SegTree tr=new SegTree(1, maxn); public static void main(String[] args) { InputReader in=new InputReader(System.in); PrintWriter out=new PrintWriter(System.out); int T=in.nextInt(); while(T-->0){ int n=in.nextInt(); int m=in.nextInt(); for(int i=1;i<=n;i++) a[i]=in.nextInt(); tr.reset(1,1, n, a); for(int i=1;i<=m;i++){ int k=in.nextInt(); int x=in.nextInt(); if (k==0){ int y=in.nextInt(); long ans=-inf; long[] res=tr.query(1,x, y); for(int j=0;j<4;j++) ans=Math.max(ans, res[j]); out.println(ans); } else{ long y=in.nextLong(); tr.update(1,x, y); } } } out.flush(); out.close(); }
}
class SegTree{ final static long inf=0x4000000000000000L; int[] l,r,mid; long[][] s; SegTree(int x,int y){ l=new int[(y-x+2)<<2]; r=new int[(y-x+2)<<2]; mid=new int[(y-x+2)<<2]; s=new long[(y-x+2)<<2][4]; build(1,x,y); } void build(int k,int x,int y){ mid[k]=(x+y)>>1; if (x<y){ build(k<<1,x, mid[k]); build(k<<1|1,mid[k]+1, y); } } void reset(int k,int x,int y,int[] a){ l[k]=x;r[k]=y;mid[k]=(x+y)>>1; if (x<y){ reset(k<<1,x, mid[k], a); reset(k<<1|1,mid[k]+1, y, a); up(s[k],s[k<<1],s[k<<1|1]); } else{ if ((mid[k]&1)>0){ s[k][0]=a[mid[k]]; s[k][1]=s[k][2]=s[k][3]=-inf; } else{ s[k][3]=a[mid[k]]; s[k][0]=s[k][1]=s[k][2]=-inf; } } } void up(long[] k,long[] l,long[] r){ k[0]=k[1]=k[2]=k[3]=-inf; k[0]=Math.max(k[0], l[0]+r[2]); k[0]=Math.max(k[0], l[1]+r[0]); k[1]=Math.max(k[1], l[1]+r[1]); k[1]=Math.max(k[1], l[0]+r[3]); k[2]=Math.max(k[2], l[2]+r[2]); k[2]=Math.max(k[2], l[3]+r[0]); k[3]=Math.max(k[3], l[3]+r[1]); k[3]=Math.max(k[3], l[2]+r[3]); k[0]=Math.max(k[0], l[0]); k[0]=Math.max(k[0], r[0]); k[1]=Math.max(k[1], l[1]); k[1]=Math.max(k[1], r[1]); k[2]=Math.max(k[2], l[2]); k[2]=Math.max(k[2], r[2]); k[3]=Math.max(k[3], l[3]); k[3]=Math.max(k[3], r[3]); } long[] query(int k,int x,int y){ long[] res=new long[4]; if (x==l[k]&&r[k]==y){ res=s[k].clone(); } else{ long[] L,R; if (x<=mid[k]) L=query(k<<1,x,Math.min(y, mid[k])).clone(); else L=new long[]{-inf,-inf,-inf,-inf}; if (mid[k]<y) R=query(k<<1|1,Math.max(mid[k]+1, x),y).clone(); else R=new long[]{-inf,-inf,-inf,-inf}; up(res,L,R); } return res; } void update(int k,int x,long d){ if (l[k]==r[k]){ if ((mid[k]&1)>0){ s[k][0]=d; s[k][1]=s[k][2]=s[k][3]=-inf; } else{ s[k][3]=d; s[k][0]=s[k][1]=s[k][2]=-inf; } return; } if (x<=mid[k]) update(k<<1,x,d); if (mid[k]<x) update(k<<1|1,x,d); up(s[k],s[k<<1],s[k<<1|1]); } }
class InputReader{ public BufferedReader reader; public StringTokenizer tokenizer;
public InputReader(InputStream stream){ reader = new BufferedReader(new InputStreamReader(stream), 32768); tokenizer = null; }
public String next(){ while(tokenizer == null || !tokenizer.hasMoreTokens()){ try{ tokenizer = new StringTokenizer(reader.readLine()); }catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken(); }
public int nextInt() { return Integer.parseInt(next()); }
public long nextLong() { return Long.parseLong(next()); } }
|