1 #include<cstdio> 2 #define MAXN 10010 3 #define MAXM 11 4 #define INF 2147483647 5 int n,k,need[MAXM]; 6 struct node 7 { 8 int big,lazy; 9 }; 10 node tree[MAXM][MAXN<<2]; 11 inline int MAX(int x,int y) 12 { 13 return x>y?x:y; 14 } 15 inline void PushUp(int t,int rt) 16 { 17 tree[t][rt].big=MAX(tree[t][rt<<1].big,tree[t][rt<<1|1].big); 18 } 19 inline void PushDown(int t,int rt) 20 { 21 if(tree[t][rt].lazy) 22 { 23 if(tree[t][rt<<1].big!=-1) 24 { 25 tree[t][rt<<1].big+=tree[t][rt].lazy; 26 tree[t][rt<<1].lazy+=tree[t][rt].lazy; 27 } 28 if(tree[t][rt<<1|1].big!=-1) 29 { 30 tree[t][rt<<1|1].big+=tree[t][rt].lazy; 31 tree[t][rt<<1|1].lazy+=tree[t][rt].lazy; 32 } 33 tree[t][rt].lazy=0; 34 } 35 } 36 void Build(int val,int t,int L,int R,int rt) 37 { 38 tree[t][rt].big=val; 39 tree[t][rt].lazy=0; 40 if(L!=R) 41 { 42 int mid=(L+R)>>1; 43 Build(val,t,L,mid,rt<<1); 44 Build(val,t,mid+1,R,rt<<1|1); 45 } 46 } 47 void Change(int t,int x,int val,int L,int R,int rt) 48 { 49 if(L==R) 50 tree[t][rt].big=val; 51 else 52 { 53 int mid=(L+R)>>1; 54 PushDown(t,rt); 55 if(x<=mid) 56 Change(t,x,val,L,mid,rt<<1); 57 else 58 Change(t,x,val,mid+1,R,rt<<1|1); 59 PushUp(t,rt); 60 } 61 } 62 void LevelUp(int t,int L,int R,int rt) 63 { 64 if(L==R) 65 { 66 int i; 67 for(i=t+1;i<=k;i++) 68 { 69 if(tree[t][rt].big>=need[i-1]&&tree[t][rt].big<need[i]) 70 break; 71 } 72 Change(i,L,tree[t][rt].big,1,n,1); 73 tree[t][rt].big=-1; 74 } 75 else 76 { 77 int mid=(L+R)>>1; 78 PushDown(t,rt); 79 if(tree[t][rt<<1].big>=need[t]) 80 LevelUp(t,L,mid,rt<<1); 81 if(tree[t][rt<<1|1].big>=need[t]) 82 LevelUp(t,mid+1,R,rt<<1|1); 83 PushUp(t,rt); 84 } 85 } 86 void Update(int t,int x,int y,int val,int L,int R,int rt) 87 { 88 if(tree[t][rt].big==-1) 89 return; 90 if(x<=L&&R<=y) 91 { 92 tree[t][rt].big+=val*t; 93 tree[t][rt].lazy+=val*t; 94 if(tree[t][rt].big>=need[t]) 95 LevelUp(t,L,R,rt); 96 } 97 else 98 { 99 int mid=(L+R)>>1; 100 PushDown(t,rt); 101 if(x<=mid) 102 Update(t,x,y,val,L,mid,rt<<1); 103 if(y>mid) 104 Update(t,x,y,val,mid+1,R,rt<<1|1); 105 PushUp(t,rt); 106 } 107 } 108 int Query(int t,int x,int y,int L,int R,int rt) 109 { 110 if(x<=L&&R<=y) 111 return tree[t][rt].big; 112 int mid=(L+R)>>1,ans=0; 113 PushDown(t,rt); 114 if(x<=mid) 115 ans=MAX(ans,Query(t,x,y,L,mid,rt<<1)); 116 if(y>mid) 117 ans=MAX(ans,Query(t,x,y,mid+1,R,rt<<1|1)); 118 return ans; 119 } 120 int main() 121 { 122 char ch; 123 int i,q,x,y,val; 124 int t,ca=1; 125 need[0]=0; 126 scanf("%d",&t); 127 while(t--) 128 { 129 scanf("%d%d%d",&n,&k,&q); 130 for(i=1;i<k;i++) 131 scanf("%d",&need[i]); 132 need[k]=INF; 133 printf("Case %d:\n",ca++); 134 Build(0,1,1,n,1); 135 for(i=2;i<=k;i++) 136 Build(-1,i,1,n,1); 137 while(q--) 138 { 139 scanf(" %c%d%d",&ch,&x,&y); 140 if(ch=='W') 141 { 142 scanf("%d",&val); 143 for(i=k;i;i--) 144 Update(i,x,y,val,1,n,1); 145 } 146 else 147 { 148 val=0; 149 for(i=k;i;i--) 150 { 151 val=MAX(val,Query(i,x,y,1,n,1)); 152 if(val) 153 break; 154 } 155 printf("%d\n",val); 156 } 157 } 158 putchar('\n'); 159 } 160 return 0; 161 }