提交时间:2025-05-11 20:16:09

运行 ID: 37849

#include<bits/stdc++.h> using namespace std; #define ll long long #define up(i,l,r) for(int i=(l);i<=(r);++i) #define down(i,l,r) for(int i=(l);i>=(r);--i) #define pi pair<int,int> #define p1 first #define p2 second #define m_p make_pair #define p_b push_back #define lb(x) (x&(-x)) #define pb push_back int read(){int x=0,f=1;char c=getchar();while(c>'9'||c<'0'){if(c=='-')f=-1;c=getchar();}while(c>='0'&&c<='9')x=x*10+c-'0',c=getchar();return x*f;} const int MAXN=600010,Mod=998244353,B=400; inline void add(int &x,int y){x+=y;if(x>=Mod)x-=Mod;} inline int Add(int x,int y){return x+y>=Mod?x+y-Mod:x+y;} int n,m,ans,bel[MAXN]; struct Sqrt{ int c[MAXN],s[MAXN],lz[MAXN],lz2[MAXN],lzc[MAXN]; void build(int x){ for(int i=(x-1)*B+1;i<=min(n,x*B);i++)add(s[i],1ll*c[i]*lz[x]%Mod),add(s[i],lz2[x]),add(c[i],lzc[x]); lz[x]=lz2[x]=lzc[x]=0; } void update(int l,int r,int x){ if(bel[l]==bel[r]){ for(int i=l;i<=r;i++)add(s[i],1ll*(c[i]+lzc[bel[l]])*x%Mod); return; } update(l,bel[l]*B,x); update((bel[r]-1)*B+1,r,x); for(int i=bel[l]+1;i<bel[r];i++)add(lz[i],x),add(lz2[i],1ll*x*lzc[i]%Mod); } void updatec(int l,int r,int x){ if(bel[l]==bel[r]){ build(bel[l]); for(int i=l;i<=r;i++)add(c[i],x); return; } updatec(l,bel[l]*B,x); updatec((bel[r]-1)*B+1,r,x); for(int i=bel[l]+1;i<bel[r];i++)add(lzc[i],x); } int qry(int x){ return (s[x]+1ll*c[x]*lz[bel[x]]+lz2[bel[x]])%Mod; } }A; int qry(int x){ int res=0; for(int i=x;i>=1;i-=lb(i)){ int tmp=0; for(int j=i+lb(i);j<=n;j+=lb(j))add(tmp,A.qry(j)); add(res,1ll*tmp*lb(i)%Mod); } return res; } #define lson (pos<<1) #define rson (pos<<1|1) struct segtree{ int t[MAXN<<2],p[MAXN<<2],c[MAXN<<2],lz[MAXN<<2],lz2[MAXN<<2],lzc[MAXN<<2]; void upd(int pos,int x,int y,int z){ add(t[pos],Add(1ll*x*c[pos]%Mod,1ll*y*p[pos]%Mod)); add(c[pos],1ll*p[pos]*z%Mod); add(lz[pos],x); add(lz2[pos],Add(y,1ll*x*lzc[pos]%Mod)); add(lzc[pos],z); } void pushup(int pos){ t[pos]=Add(t[lson],t[rson]); c[pos]=Add(c[lson],c[rson]); } void pushdown(int pos){ upd(lson,lz[pos],lz2[pos],lzc[pos]); upd(rson,lz[pos],lz2[pos],lzc[pos]); lz[pos]=lz2[pos]=lzc[pos]=0; } void build(int pos,int l,int r){ if(l==r){ c[pos]=p[pos]=lb(l); return; } int mid=(l+r)>>1; build(lson,l,mid);build(rson,mid+1,r); pushup(pos); p[pos]=Add(p[lson],p[rson]); } void update(int pos,int l,int r,int ql,int qr,int x,int c){ if(ql<=l&&qr>=r){ upd(pos,x,0,c); return; } pushdown(pos); int mid=(l+r)>>1; if(ql<=mid)update(lson,l,mid,ql,qr,x,c); if(qr>mid)update(rson,mid+1,r,ql,qr,x,c); pushup(pos); } int query(int pos,int l,int r,int ql,int qr){ if(ql<=l&&qr>=r)return t[pos]; pushdown(pos); int mid=(l+r)>>1; if(qr<=mid)return query(lson,l,mid,ql,qr); if(ql>mid)return query(rson,mid+1,r,ql,qr); return Add(query(lson,l,mid,ql,qr),query(rson,mid+1,r,ql,qr)); } }D; void slv(){ m=read(); n=1; while(n<m)n<<=1; m=read(); D.build(1,1,n); for(int i=1;i<=n;i++)bel[i]=(i-1)/B+1,A.c[i]=1; for(int i=1;i<=bel[n];i++)A.build(i); while(m--){ int op=read(),l=read(),r=read(),x=op==2?0:read(); if(op==1)A.updatec(l,r,x),D.update(1,1,n,l,r,0,x); if(op==2)printf("%d\n",Add(Add(qry(r)-qry(l-1),Mod),D.query(1,1,n,l,r))); if(op==3)A.update(l,r,x),D.update(1,1,n,l,r,x,0); } } signed main(){ // freopen("1.in","r",stdin);freopen("1.out","w",stdout); // int _=read();while(_--) slv(); // system("grep VmPeak /proc/$PPID/status"); // cerr<<(clock()*1.0/CLOCKS_PER_SEC)<<"s"<<endl; return 0; }