记录编号 |
384251 |
评测结果 |
AAAAAAAAAA |
题目名称 |
[HZOI 2016] 数列操作d |
最终得分 |
100 |
用户昵称 |
AntiLeaf |
是否通过 |
通过 |
代码语言 |
C++ |
运行时间 |
0.870 s |
提交时间 |
2017-03-17 20:20:16 |
内存使用 |
4.87 MiB |
显示代码纯文本
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int maxn=300010,p=1000000007,inv_2=500000004;
void add(int,int,int*);
int query(int,int*);
int sum(int);
int n,m,c[3][maxn],sq[maxn],l,r,d;
int main(){
freopen("segment.in","r",stdin);
freopen("segment.out","w",stdout);
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++)sq[i]=(long long)i*i%p;
while(m--){
scanf("%d%d%d",&d,&l,&r);
if(d){
scanf("%d",&d);
d=(long long)(d%p)*inv_2%p;
add(l,(sq[l]-l)%p*(long long)d%p,c[0]);
add(r+1,(sq[r]+(long long)(1-(l<<1))*r%p)%p*(long long)d%p,c[0]);
add(l,(long long)(1-(l<<1))*d%p,c[1]);
add(r+1,-((long long)(1-(l<<1))*d%p),c[1]);
add(l,d,c[2]);
add(r+1,-d,c[2]);
}
else printf("%d\n",((sum(r)-sum(l-1))%p+p)%p);
}
return 0;
}
void add(int x,int d,int *c){
while(x<=n){
c[x]=(c[x]+d)%p;
x+=x&-x;
}
}
int query(int x,int *c){
int ans=0;
while(x){
ans=(ans+c[x])%p;
x&=x-1;
}
return ans;
}
inline int sum(int x){return ((query(x,c[0])+(long long)x*query(x,c[1])%p)%p+(long long)sq[x]*query(x,c[2])%p)%p;}