标签:png ++ turn define names amp load cin false
动态加点线段树,标记永久化好写常数小
#include<bits/stdc++.h>
#define fi first
#define se second
#define lson l,mid,p<<1
#define rson mid+1,r,p<<1|1
#define pb push_back
#define ll long long
using namespace std;
const ll inf=1e18;
const int mod=1e9+7;
const int maxn=1e7+10;
int n,m;
ll tr[maxn];
int ls[maxn],rs[maxn],tag[maxn],tot;
int rt;
void up(ll x,ll y,ll l,ll r,int &p,ll k){
tr[++tot]=(tr[p]+(y-x+1)%mod*k%mod)%mod;
ls[tot]=ls[p],rs[tot]=rs[p],tag[tot]=tag[p],p=tot;
if(x==l&&y==r){
tag[p]=(tag[p]+k)%mod;
return;
}ll mid=l+r>>1;
if(y<=mid) up(x,y,l,mid,ls[p],k);
else if(x>mid) up(x,y,mid+1,r,rs[p],k);
else up(x,mid,l,mid,ls[p],k),up(mid+1,y,mid+1,r,rs[p],k);
}
ll qy(ll x,ll y,ll l,ll r,int p,ll k){
if(x==l&&y==r){
return (tr[p]+(y-x+1)%mod*k%mod)%mod;
}ll mid=l+r>>1;
if(y<=mid) return qy(x,y,l,mid,ls[p],(k+tag[p])%mod);
else if(x>mid) return qy(x,y,mid+1,r,rs[p],(k+tag[p])%mod);
else return (qy(x,mid,l,mid,ls[p],(k+tag[p])%mod)+qy(mid+1,y,mid+1,r,rs[p],(k+tag[p])%mod))%mod;
}
int main(){
//ios::sync_with_stdio(false);
//freopen("in","r",stdin);
cin>>m;
for(int i=1,op;i<=m;i++){
ll x,l,r;scanf("%d%lld%lld",&op,&l,&r);
if(op==1){
scanf("%lld",&x);
x%=mod;
up(l,r,1,inf,rt,x);
}else{
printf("%lld\n",qy(l,r,1,inf,rt,0));
}
}
return 0;
}
标签:png ++ turn define names amp load cin false
原文地址:https://www.cnblogs.com/xyq0220/p/11509716.html