记录编号 384008 评测结果 AAAAAAAAAA
题目名称 [HZOI 2016] 数列操作d 最终得分 100
用户昵称 Gravatar河北交通广播992大师来了 是否通过 通过
代码语言 C++ 运行时间 4.204 s
提交时间 2017-03-16 20:44:13 内存使用 36.94 MiB
显示代码纯文本
#include <stdio.h>
#include <ctime>
#include <algorithm>
#include <cstring>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdlib>
#include <iostream>
#include <bitset>
#include <cmath>
#include <vector>
#define Mem(a, b) memset(a, b, sizeof a)
#define Mcpy(a, b) memcpy(a, b, sizeof a)
#define RG register
#define IL inline
using namespace std;
typedef long long LL;
typedef unsigned int uint;
typedef unsigned long long ull;
IL void qkin(RG int &res){
	RG int x,f=1; RG char ch;
	while(ch=getchar(),ch<'0'||ch>'9')if(ch=='-')f=-1;x=ch-48;
	while(ch=getchar(),ch>='0'&&ch<='9')x=x*10+ch-48;res=x*f;}
IL void read(RG int &A){ qkin(A); }
IL void read(RG int &A,RG int &B){ qkin(A),qkin(B); }
IL void read(RG int &A,RG int &B,RG int &C){ qkin(A),qkin(B),qkin(C); }
#define Gets(s) scanf("%s", s+1);
const double INF = 1e60;
const int inf = 0x7f7f7f7f;
const double Pi = acos(-1);
const double eps = 1e-8;
const int maxn = 300010*4;
#define int LL
const int mod = 1000000007;
int n,m,op,s,t,ans;
int lazy1[maxn],lazy2[maxn],sum[maxn],tot[maxn];

#define lc rt<<1
#define rc rt<<1|1
#define mid (((l)+(r))>>(1))
#define lson lc,l,mid
#define rson rc,mid+1,r

void build(int rt,int l,int r){
	if(l == r){
		tot[rt] = l; return;
	}
	build(lson); build(rson);
	tot[rt] = tot[lc] + tot[rc];
}
void update(int rt,int l,int r){
	int x = lazy1[rt], y = lazy2[rt];
	if(!x && !y) return;
	lazy1[rt] = lazy2[rt] = 0;
	lazy1[lc] += x; lazy2[lc] += y; lazy1[lc] %= mod; lazy2[lc] %= mod;
	lazy1[rc] += x; lazy2[rc] += y; lazy1[rc] %= mod; lazy2[rc] %= mod;
	sum[lc] += tot[lc] * x - (mid-l+1) * y + mod; sum[lc] %= mod;
	sum[rc] += tot[rc] * x - (r-mid) * y + mod; sum[rc] %= mod;
}
void add(int x,int y,int rt,int l,int r){
	if(s<=l && t>=r){
		lazy2[rt] += y;	lazy2[rt] %= mod;
		lazy1[rt] += x; lazy1[rt] %= mod;
		sum[rt] += (tot[rt] * x - (r-l+1) * y + mod) % mod;
		return;
	}
	update(rt, l, r);
	if(s<=mid) add(x, y, lson);
	if(t> mid) add(x, y, rson);
	sum[rt] = (sum[lc] + sum[rc]) % mod;
}
int query(int rt,int l,int r){
	if(s<=l && t>=r) return sum[rt];
	update(rt, l, r);
	if(t<=mid) return query(lson);
	if(s> mid) return query(rson);
	return (query(lson) + query(rson)) % mod;
}
signed main(){
#define HAHA LALA
#ifdef HAHA	
	freopen("segment.in", "r", stdin);
	freopen("segment.out", "w", stdout);
#endif
	scanf("%lld%lld", &n, &m);
	int x;
	build(1, 1, n);
	for(int i=1; i<=m; i++){
		scanf("%lld%lld%lld", &op, &s, &t);
		if(op == 1) {
			scanf("%lld", &x);
			add(x, s*x, 1, 1, n);
		} else {
			ans = query(1, 1, n);
			while(ans < 0) ans += mod; ans %= mod;
			printf("%lld\n", ans);
		}
	}
	return 0;
}