记录编号 156689 评测结果 AAAAAAAAAA
题目名称 [HAOI 2012]高速公路 最终得分 100
用户昵称 GravatarAsm.Def 是否通过 通过
代码语言 C++ 运行时间 1.692 s
提交时间 2015-04-05 18:52:56 内存使用 0.28 MiB
显示代码纯文本
/***********************************************************************/
/**********************By Asm.Def-Wu Jiaxin*****************************/
/***********************************************************************/
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <cctype>
#include <algorithm>
using namespace std;
#define SetFile(x) ( freopen(#x".in", "r", stdin), freopen(#x".out", "w", stdout) );
#define getc() getchar() 
template<class T>inline void getd(T &x){
	char ch = getc();bool neg = false;
	while(!isdigit(ch) && ch != '-')ch = getc();
	if(ch == '-')ch = getc(), neg = true;
	x = ch - '0';
	while(isdigit(ch = getc()))x = x * 10 - '0' + ch;
	if(neg)x = -x;
}
/***********************************************************************/
typedef long long LL;
LL gcd(LL x, LL y){return !x ? y : gcd(y % x, x);}
struct Data{
	LL val, vali, vali2;
	Data():val(0),vali(0),vali2(0){}
	Data(LL a, LL b, LL c):val(a),vali(b),vali2(c){}
	Data operator + (const Data &b){return Data(val+b.val, vali+b.vali, vali2+b.vali2);}
};

struct SegT{
	int L, R, mid;LL tag, len, S, S2;
	Data data;
	SegT *son[2];
	SegT(int l, int r):L(l),R(r),mid((l+r)>>1),tag(0){
		len = r - l, S = (len * (l+r-1))>>1, S2 = len*((LL)r*(r+l)+(LL)l*l-1)/3-S;
		if(len == 1)return;
		son[0] = new SegT(l, mid), son[1] = new SegT(mid, r);
	}
	inline void push(){
		data.val += tag * len;
		data.vali += tag * S;
		data.vali2 += tag * S2;
		if(len > 1)son[0]->tag += tag, son[1]->tag += tag;
		tag = 0;
	}
	void Add(int l, int r, int x){
		if(L == l && R == r){tag += x;push();return;}
		if(tag)push();
		if(r <= mid)son[0]->Add(l, r, x);
		else if(l >= mid)son[1]->Add(l, r, x);
		else son[0]->Add(l, mid, x), son[1]->Add(mid, r, x);
		if(son[0]->tag)son[0]->push();if(son[1]->tag)son[1]->push();
		data = son[0]->data + son[1]->data;
	}
	Data Query(int l, int r){
		if(tag)push();
		if(L == l && R == r)return data;
		if(r <= mid)return son[0]->Query(l, r);
		if(l >= mid)return son[1]->Query(l, r);
		return son[0]->Query(l, mid) + son[1]->Query(mid, r);
	}
}*Root;

inline void work(){
	int N, M, l, r, x, opt;getd(N), getd(M);
	Root = new SegT(1, N);
	Data tmp;
	LL s, tot, d;
	while(M--){
		while((opt = getchar()) < 'A');
		if(opt == 'C'){
			getd(l), getd(r), getd(x);
			Root->Add(l, r, x);
		}
		else{
			getd(l), getd(r);
			tmp = Root->Query(l, r);--l;
			s = tmp.vali * (l + r) - tmp.vali2 - tmp.val * l * r;
			d = r - l;tot = ((d * (d - 1)) >> 1);
			d = gcd(s, tot);s /= d, tot /= d;
			printf("%lld/%lld\n", s, tot);
		}
	}
}

int main(){

#ifdef DEBUG
	freopen("test.txt", "r", stdin);
#elif !defined ONLINE_JUDGE
	SetFile(roadxw);
#endif
	
	work();

#ifdef DEBUG
	printf("\n%lf sec \n", (double)clock() / CLOCKS_PER_SEC);
#endif
	return 0;
}