1 #include<cstdio> 2 #define MAXN 200010 3 #define INF 987654321 4 int a[MAXN],s[MAXN],tree[MAXN<<2],lazy[MAXN<<2],k; 5 inline int MAX(int x,int y) 6 { 7 return x>y?x:y; 8 } 9 inline int MIN(int x,int y) 10 { 11 return x>y?y:x; 12 } 13 inline void swap(int &x,int &y) 14 { 15 int temp=x; 16 x=y; 17 y=temp; 18 } 19 inline void PushUp(int rt) 20 { 21 tree[rt]=MAX(tree[rt<<1],tree[rt<<1|1]); 22 } 23 void Build(int L,int R,int rt) 24 { 25 lazy[rt]=0; 26 if(L==R) 27 tree[rt]=s[L+k-1]-s[L-1]; 28 else 29 { 30 int mid=(L+R)>>1; 31 Build(L,mid,rt<<1); 32 Build(mid+1,R,rt<<1|1); 33 PushUp(rt); 34 } 35 } 36 inline void PushDown(int rt) 37 { 38 if(lazy[rt]) 39 { 40 tree[rt<<1]+=lazy[rt]; 41 tree[rt<<1|1]+=lazy[rt]; 42 lazy[rt<<1]+=lazy[rt]; 43 lazy[rt<<1|1]+=lazy[rt]; 44 lazy[rt]=0; 45 } 46 } 47 void Update(int x,int y,int z,int L,int R,int rt) 48 { 49 if(x<=L&&R<=y) 50 { 51 lazy[rt]+=z; 52 tree[rt]+=z; 53 } 54 else 55 { 56 int mid=(L+R)>>1; 57 PushDown(rt); 58 if(mid>=x) 59 Update(x,y,z,L,mid,rt<<1); 60 if(y>mid) 61 Update(x,y,z,mid+1,R,rt<<1|1); 62 PushUp(rt); 63 } 64 } 65 int Query(int x,int y,int L,int R,int rt) 66 { 67 if(x<=L&&R<=y) 68 return tree[rt]; 69 int ans=-INF,mid=(L+R)>>1; 70 PushDown(rt); 71 if(mid>=x) 72 ans=MAX(ans,Query(x,y,L,mid,rt<<1)); 73 if(y>mid) 74 ans=MAX(ans,Query(x,y,mid+1,R,rt<<1|1)); 75 return ans; 76 } 77 int main() 78 { 79 int n,m,c,i,p,x,y; 80 scanf("%d",&c); 81 while(c--) 82 { 83 scanf("%d%d%d",&n,&m,&k); 84 s[0]=0; 85 for(i=1;i<=n;i++) 86 { 87 scanf("%d",&a[i]); 88 s[i]=s[i-1]+a[i]; 89 } 90 n-=k-1; 91 Build(1,n,1); 92 while(m--) 93 { 94 scanf("%d%d%d",&p,&x,&y); 95 if(p==0) 96 { 97 if(a[x]!=y) 98 { 99 Update(MAX(1,x-k+1),x,y-a[x],1,n,1); 100 a[x]=y; 101 } 102 } 103 else if(p==1) 104 { 105 if(x!=y) 106 { 107 Update(MAX(1,x-k+1),x,a[y]-a[x],1,n,1); 108 Update(MAX(1,y-k+1),y,a[x]-a[y],1,n,1); 109 swap(a[x],a[y]); 110 } 111 } 112 else 113 printf("%d\n",Query(x,y-k+1,1,n,1)); 114 } 115 } 116 return 0; 117 }