加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

HFUUOJ1024 动态开点线段树+标记永久化

发布时间:2020-12-16 09:16:14 所属栏目:百科 来源:网络整理
导读:题意 分析 动态加点线段树,标记永久化好写常数小 Code #includebits/stdc++.h#define fi first#define se second#define lson l,mid,p1#define rson mid+1,r,p1|1#define pb push_back#define ll long longusing namespace std;const ll inf=1e18;const int

题意

分析

动态加点线段树,标记永久化好写常数小

Code

#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,ls[p],k);
    else if(x>mid) up(x,mid+1,rs[p],k);
    else up(x,k),up(mid+1,k);
}
ll qy(ll x,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,(k+tag[p])%mod);
    else if(x>mid) return qy(x,(k+tag[p])%mod);
    else return (qy(x,(k+tag[p])%mod)+qy(mid+1,(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,r;scanf("%d%lld%lld",&op,&l,&r);
        if(op==1){
            scanf("%lld",&x);
            x%=mod;
            up(l,1,inf,rt,x);
        }else{
            printf("%lldn",qy(l,0));
        }
    }
    return 0;
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读