比赛 cdcqの省选膜你赛 评测结果 AAAAAAAAAAAAAAAAAAAA
题目名称 新史「新幻想史 -现代史-」 最终得分 100
用户昵称 Cydiater 运行时间 5.288 s
代码语言 C++ 内存使用 14.04 MiB
提交时间 2017-04-11 12:28:55
显示代码纯文本
//A
//by Cydiater
//2017.4.11
#include <cstdio>
#include <iostream>
#include <bitset>
#include <set>
#include <iomanip>
#include <queue>
#include <map>
#include <algorithm>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <cstdlib>
#include <vector>
#include <complex>

using namespace std;

#define ll long long
#define up(i,j,n)	for(int i=j;i<=n;i++)
#define down(i,j,n)	for(int i=j;i>=n;i--)
#define cmax(a,b)	a=max(a,b)
#define cmin(a,b)	a=min(a,b)
#define FILE		"cdcq_a"

const int MAXN=1e5+5;
const int oo=0x3f3f3f3f;

int N,M;
ll val[MAXN],ans[MAXN],sum[MAXN];

char s[5];

struct query{
	int op,x,y,z,l,r,v,t,p;
}qry[MAXN],tmp[MAXN];

namespace SGT{
	struct tree{
		ll tag,sum;
	}t[MAXN<<2];
	inline void mark(int L,int R,int k,ll tag){
		t[k].tag+=tag;
		t[k].sum+=tag*(R-L+1);
	}
	void Pushdown(int L,int R,int k){
		ll tag=t[k].tag;
		int mid=(L+R)>>1;
		mark(L,mid,k<<1,tag);
		mark(mid+1,R,k<<1|1,tag);
		t[k].tag=0;
	}
	inline void reload(int k){
		t[k].sum=t[k<<1].sum+t[k<<1|1].sum;
	}
	void Modify(int leftt,int rightt,int k,int L,int R,ll tag){
		if(leftt!=rightt)Pushdown(leftt,rightt,k);
		if(leftt>=L&&rightt<=R){
			mark(leftt,rightt,k,tag);
			return;
		}
		int mid=(leftt+rightt)>>1;
		if(L<=mid)	Modify(leftt,mid,k<<1,L,R,tag);
		if(R>=mid+1)	Modify(mid+1,rightt,k<<1|1,L,R,tag);
		reload(k);
	}
	ll Query(int leftt,int rightt,int k,int L,int R){
		if(leftt!=rightt)Pushdown(leftt,rightt,k);
		if(leftt>=L&&rightt<=R)	return t[k].sum;
		int mid=(leftt+rightt)>>1;
		ll res=0;
		if(L<=mid)	res+=Query(leftt,mid,k<<1,L,R);
		if(mid+1<=R)	res+=Query(mid+1,rightt,k<<1|1,L,R);
		return res;
	}
}using namespace SGT;

namespace solution{
	void CDQ(int L,int R){
		int mid=(L+R)>>1;
		if(L==R){
			if(qry[mid].op==0){
				if(ans[qry[mid].p]==-1)ans[qry[mid].p]=0;
				ans[qry[mid].p]+=sum[qry[mid].y]-sum[qry[mid].x-1];
			}
			return;
		}
		CDQ(L,mid);CDQ(mid+1,R);
		int p=L,q;
		up(i,mid+1,R){
			while(p<=mid&&qry[p].t<=qry[i].t){
				if(qry[p].op==1){
					Modify(1,N,1,qry[p].x,qry[p].y,-qry[p].z);
					Modify(1,N,1,qry[p].l,qry[p].r,qry[p].v);
				}
				p++;
			}
			if(qry[i].op==0)ans[qry[i].p]+=Query(1,N,1,qry[i].x,qry[i].y);
		}
		up(i,L,p-1)if(qry[i].op==1){
			Modify(1,N,1,qry[i].x,qry[i].y,qry[i].z);
			Modify(1,N,1,qry[i].l,qry[i].r,-qry[i].v);
		}
		p=L;q=mid+1;
		up(i,L,R){
			if(p>mid||(q<=R&&(qry[p].t>qry[q].t||(qry[p].t==qry[q].t&&qry[q].op==1))))	tmp[i]=qry[q++];
			else 										tmp[i]=qry[p++];
		}
		up(i,L,R)qry[i]=tmp[i];
	}
	void Prepare(){
		scanf("%d%d",&N,&M);
		up(i,1,N)scanf("%d",&val[i]);
		up(i,1,N)sum[i]=sum[i-1]+val[i];
		memset(ans,-1,sizeof(ans));
		int x,y,z,l,r,v,t;
		up(i,1,M){
			scanf("%s",s);
			if(s[0]=='Q'){
				scanf("%d%d%d",&x,&y,&z);
				qry[i]=(query){0,x,y,0,0,0,0,z,i};
			}
			if(s[0]=='M'){
				scanf("%d%d%d%d%d%d%d",&x,&y,&z,&l,&r,&v,&t);
				qry[i]=(query){1,x,y,z,l,r,v,t,i};
			}
		}
	}
	void Solve(){
		CDQ(1,M);
		up(i,1,M)if(ans[i]!=-1)printf("%lld\n",ans[i]);
	}
}

int main(){
	freopen(FILE".in","r",stdin);
	freopen(FILE".out","w",stdout);
	using namespace solution;
	Prepare();
	Solve();
	return 0;
}