记录编号 545726 评测结果 AAAAAAAAAA
题目名称 [HAOI 2012]高速公路 最终得分 100
用户昵称 Gravatar瑆の時間~無盡輪迴·林蔭 是否通过 通过
代码语言 C++ 运行时间 1.067 s
提交时间 2019-11-01 12:06:25 内存使用 27.19 MiB
显示代码纯文本
#include<iostream>
#include<cstdio>
#include<vector>
#define int long long int
using namespace std;
struct PE
{
	int lazy,sum1,sum2,sum3,sum4,sum5,l,r;
	//sum1=∑a[i]
	//sum2=∑a[i]*i
	//sum3=∑a[i]*i*i
	//sum4=∑i;
	//sum5=∑i*i;
	//4,5用于更新2,3 
};
PE t[400001];
int a[100001];
int n,m,a1,a2,a3;
char xd;
int ls(int x)
{
	return x<<1;
}
int rs(int x)
{
	return x<<1|1;
}
void pushup(int x)
{
	t[x].sum1=t[ls(x)].sum1+t[rs(x)].sum1;
	t[x].sum2=t[ls(x)].sum2+t[rs(x)].sum2;
	t[x].sum3=t[ls(x)].sum3+t[rs(x)].sum3;
	
	t[x].l=t[ls(x)].l;
	t[x].r=t[rs(x)].r;
}
void build(int x,int l,int r)
{
	if(l==r)
	{
		t[x].sum1=a[l];
		t[x].sum2=a[l]*l;
		t[x].sum3=a[l]*l*l;
		t[x].sum4=l;
		t[x].sum5=l*l;
		t[x].lazy=0;
		t[x].l=t[x].r=l;
		return ; 
	}
	int mid=(l+r)>>1;
	build(ls(x),l,mid);
	build(rs(x),mid+1,r);
	t[x].sum4=t[ls(x)].sum4+t[rs(x)].sum4;
	t[x].sum5=t[ls(x)].sum5+t[rs(x)].sum5;
	pushup(x);
}
void pushdown(int x,int l,int r)
{
	int mid=(l+r)>>1;
	if(t[x].lazy)
	{
		t[ls(x)].lazy+=t[x].lazy;
		t[rs(x)].lazy+=t[x].lazy;
		t[ls(x)].sum1+=(mid-l+1)*t[x].lazy;
		t[rs(x)].sum1+=(r-mid)*t[x].lazy;
		t[ls(x)].sum2+=(t[ls(x)].sum4*t[x].lazy);
		t[ls(x)].sum3+=(t[ls(x)].sum5*t[x].lazy);
		t[rs(x)].sum2+=(t[rs(x)].sum4*t[x].lazy);
		t[rs(x)].sum3+=(t[rs(x)].sum5*t[x].lazy);
		t[x].lazy=0;
	}
}
void QZADD(int x,int l,int r,int nl,int nr,int w)
{
	if(nl<=l&&nr>=r)
	{
		t[x].sum1+=(r-l+1)*w;
		t[x].sum2+=(t[x].sum4*w);
		t[x].sum3+=(t[x].sum5*w);
		t[x].lazy+=w;
		return;
	}
	pushdown(x,l,r);
	int mid=(l+r)>>1;
	if(nl<=mid)
		QZADD(ls(x),l,mid,nl,nr,w);
	if(nr>mid)
		QZADD(rs(x),mid+1,r,nl,nr,w);
	pushup(x);
}
int QZQUERY1(int x,int l,int r,int nl,int nr)
{
	int kel=0;
	if(nl<=l&&nr>=r)
	{
		return t[x].sum1;
	}
	pushdown(x,l,r);
	int mid=(l+r)>>1;
	if(nl<=mid)
		kel+=QZQUERY1(ls(x),l,mid,nl,nr);
	if(nr>mid)
		kel+=QZQUERY1(rs(x),mid+1,r,nl,nr);
	return kel;
}
int QZQUERY2(int x,int l,int r,int nl,int nr)
{
	int kel=0;
	if(nl<=l&&nr>=r)
	{
		return t[x].sum2;
	}
	pushdown(x,l,r);
	int mid=(l+r)>>1;
	if(nl<=mid)
		kel+=QZQUERY2(ls(x),l,mid,nl,nr);
	if(nr>mid)
		kel+=QZQUERY2(rs(x),mid+1,r,nl,nr);
	return kel;
}
int QZQUERY3(int x,int l,int r,int nl,int nr)
{
	int kel=0;
	if(nl<=l&&nr>=r)
	{
		return t[x].sum3;
	}
	pushdown(x,l,r);
	int mid=(l+r)>>1;
	if(nl<=mid)
		kel+=QZQUERY3(ls(x),l,mid,nl,nr);
	if(nr>mid)
		kel+=QZQUERY3(rs(x),mid+1,r,nl,nr);
	return kel;
}
int QUERY(int l,int r)
{
	int s=0;
	s+=QZQUERY1(1,1,n,l,r)*(r-l-r*l+1);
	//cout<<QZQUERY1(1,1,n,l,r)<<' ';
	s+=QZQUERY2(1,1,n,l,r)*(l+r);
	//cout<<QZQUERY2(1,1,n,l,r)<<' ';
	s-=QZQUERY3(1,1,n,l,r);
	//cout<<QZQUERY3(1,1,n,l,r)<<'*'<<endl;
	return s;
}
int GCD(int x,int y)
{
	return y==0?x:GCD(y,x%y);
}
int LINYIN()
{
	freopen("roadxw.in","r",stdin);
	freopen("roadxw.out","w",stdout);
	scanf("%lld%lld",&n,&m);
	build(1,1,n);
	for(int i=1;i<=m;i++)
	{
		cin>>xd;
		if(xd=='C')
		{
			scanf("%lld%lld%lld",&a1,&a2,&a3);
			QZADD(1,1,n,a1+1,a2,a3);
		}
		else
		{
			scanf("%d%d",&a1,&a2);
			int kel=QUERY(a1+1,a2);
			int s=(a2-a1+1)*(a2-a1)/2;
			int G=GCD(s,kel);
			//cout<<endl<<kel<<' '<<s<<' '<<G<<endl; 
			printf("%lld/%lld\n",kel/G,s/G);
		}
	}
	return 0;
}
int LWH=LINYIN();
signed main()
{
	;
}