$ans=\sum\limits_{i=l}^{r-1}v[i]*(i-l+1)*(r-i)\\=r*\sum\limits_{i=l}^{r-1}v[i]*(i-l+1)-\sum\limits_{i=l}^{r-1}v[i]*i*(i-l+1)\\=(r+l-1)*\sum\limits_{i=l}^{r-1}v[i]*i-r*(l-1)\sum\limits_{i=l}^{r-1}v[i]-\sum\limits_{i=l}^{r-1}v[i]*i*i$
#include <cstdio>
#include <cstring>
#include <iostream>
#define lson x<<1
#define rson x<<1|1
using namespace std;
typedef long long ll;
//-(l-1)*r*v[i]+(r+l-1)*v[i]*i-v[i]*i*i
int n,m;
char str[5];
const int maxn=400010;
struct sag
{
int flag;
ll siz[maxn],s[maxn],tag[maxn];
void build(int l,int r,int x)
{
if(l==r)
{
if(flag==0) siz[x]=1;
if(flag==1) siz[x]=l;
if(flag==2) siz[x]=(ll)l*l;
return ;
}
int mid=l+r>>1;
build(l,mid,lson),build(mid+1,r,rson);
siz[x]=siz[lson]+siz[rson];
}
void pushdown(int x)
{
if(tag[x])
{
s[lson]+=siz[lson]*tag[x],s[rson]+=siz[rson]*tag[x];
tag[lson]+=tag[x],tag[rson]+=tag[x],tag[x]=0;
}
}
void updata(int l,int r,int x,int a,int b,ll c)
{
if(a<=l&&r<=b)
{
s[x]+=siz[x]*c,tag[x]+=c;;
return ;
}
pushdown(x);
int mid=l+r>>1;
if(a<=mid) updata(l,mid,lson,a,b,c);
if(b>mid) updata(mid+1,r,rson,a,b,c);
s[x]=s[lson]+s[rson];
}
ll query(int l,int r,int x,int a,int b)
{
if(a<=l&&r<=b) return s[x];
pushdown(x);
int mid=l+r>>1;
if(b<=mid) return query(l,mid,lson,a,b);
if(a>mid) return query(mid+1,r,rson,a,b);
return query(l,mid,lson,a,b)+query(mid+1,r,rson,a,b);
}
}s0,s1,s2;
ll gcd(ll a,ll b)
{
return (!b)?a:gcd(b,a%b);
}
int rd()
{
int ret=0,f=1; char gc=getchar();
while(gc<‘0‘||gc>‘9‘) {if(gc==‘-‘) f=-f; gc=getchar();}
while(gc>=‘0‘&&gc<=‘9‘) ret=ret*10+gc-‘0‘,gc=getchar();
return ret*f;
}
int main()
{
n=rd(),m=rd();
s0.flag=0,s1.flag=1,s2.flag=2,s0.build(1,n,1),s1.build(1,n,1),s2.build(1,n,1);
int i,l,r,v;
ll a,b,g;
for(i=1;i<=m;i++)
{
scanf("%s",str);
if(str[0]==‘C‘)
{
l=rd(),r=rd()-1,v=rd();
s0.updata(1,n,1,l,r,v),s1.updata(1,n,1,l,r,v),s2.updata(1,n,1,l,r,v);
}
else
{
l=rd(),r=rd();
a=-(ll)(l-1)*r*s0.query(1,n,1,l,r-1)+(r+l-1)*s1.query(1,n,1,l,r-1)-s2.query(1,n,1,l,r-1);
b=(ll)(r-l+1)*(r-l)/2,g=gcd(a,b),a/=g,b/=g;
printf("%lld/%lld\n",a,b);
}
}
return 0;
}