Time Limit: 10000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1846 Accepted Submission(s): 520
//#pragma comment(linker,"/STACK:65536000") #include <stdio.h> #include <string.h> #include <math.h> #include <stdlib.h> #include <iostream> #include <queue> #include <stack> #include <string> #include <map> #include <vector> #include <algorithm> #define N 10005 #define M #define E #define inf 0x3f3f3f3f #define eps 1e-8 #define linf (LL)1<<60 #define dinf 1e20 #define LL long long #define clr(a,b) memset(a,b,sizeof(a)) #define D(a) ((a)*(a)) using namespace std; struct Lt { int le,ri,val[12],flag,rst; }lt[N*6]; int lim[12],n,k,q; void build(int rt,int le,int ri) { lt[rt].le=le; lt[rt].ri=ri; clr(lt[rt].val,-1); lt[rt].val[1]=0; lt[rt].flag=0; lt[rt].rst=0; if(le==ri)return ; int mid=(le+ri)>>1; build(rt<<1,le,mid); build(rt<<1|1,mid+1,ri); } void update(int rt,int le,int ri,int rst) { if(lt[rt].le==lt[rt].ri) { lt[rt].flag=1; int id; for(id=1;id<=k;id++)if(~lt[rt].val[id])break; int v=(lt[rt].rst+rst)*id+lt[rt].val[id]; lt[rt].val[id]=-1; for(id=1;id<k;id++)if(v<lim[id])break; lt[rt].val[id]=v; lt[rt].rst=0; return ; } if(lt[rt].le==le&<[rt].ri==ri) { int f=0; for(int i=1;i<k&&!f;i++) if(~lt[rt].val[i]&<[rt].val[i]+i*(lt[rt].rst+rst)>=lim[i]) f=1; if(!f) { lt[rt].rst+=rst; lt[rt].flag=1; return ; } } if(lt[rt].flag) { update(rt<<1,lt[rt<<1].le,lt[rt<<1].ri,lt[rt].rst); update(rt<<1|1,lt[rt<<1|1].le,lt[rt<<1|1].ri,lt[rt].rst); lt[rt].flag=0;clr(lt[rt].val,-1);lt[rt].rst=0; } int mid=(lt[rt].le+lt[rt].ri)>>1; if(ri<=mid)update(rt<<1,le,ri,rst); else if(le>mid)update(rt<<1|1,le,ri,rst); else { update(rt<<1,le,mid,rst); update(rt<<1|1,mid+1,ri,rst); } for(int i=1;i<=k;i++) { if(~lt[rt<<1].val[i]&&~lt[rt<<1|1].val[i]) lt[rt].val[i]=max(lt[rt<<1].val[i]+i*lt[rt<<1].rst,lt[rt<<1|1].val[i]+i*lt[rt<<1|1].rst); else if(~lt[rt<<1].val[i])lt[rt].val[i]=lt[rt<<1].val[i]+i*lt[rt<<1].rst; else if(~lt[rt<<1|1].val[i])lt[rt].val[i]=lt[rt<<1|1].val[i]+i*lt[rt<<1|1].rst; else lt[rt].val[i]=-1; } } int query(int rt,int le,int ri,int rst) { if(lt[rt].le==le&<[rt].ri==ri) { for(int i=k;i>=1;i--) if(~lt[rt].val[i]) return lt[rt].val[i]+lt[rt].rst*i+rst*i; } if(lt[rt].flag)rst+=lt[rt].rst; int mid=(lt[rt].le+lt[rt].ri)>>1; if(ri<=mid)return query(rt<<1,le,ri,rst); else if(le>mid)return query(rt<<1|1,le,ri,rst); else return max(query(rt<<1,le,mid,rst),query(rt<<1|1,mid+1,ri,rst)); } int main() { //freopen("/home/fatedayt/in","r",stdin); //freopen("/home/fatedayt/out1","w",stdout); int ncase; scanf("%d",&ncase); for(int h=1;h<=ncase;h++) { scanf("%d%d%d",&n,&k,&q); for(int i=1;i<k;i++)scanf("%d",&lim[i]); build(1,1,n); printf("Case %d:\n",h); for(int i=1;i<=q;i++) { char d[3]; scanf("%s",d); if(d[0]=='W') { int a,b,c; scanf("%d%d%d",&a,&b,&c); update(1,a,b,c); a++; } else { int a,b; scanf("%d%d",&a,&b); printf("%d\n",query(1,a,b,0)); } } puts(""); } return 0; }