Run ID | 作者 | 问题 | 语言 | 测评结果 | 分数 | 时间 | 内存 | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|---|
37845 | baka24 | 【S】T3 | C++ | 运行超时 | 60 | 2000 MS | 46356 KB | 4676 | 2025-05-11 19:25:46 |
#include<bits/stdc++.h> using namespace std; #define ll long long #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=800; void add(int &x,int y){x+=y;if(x>=Mod)x-=Mod;if(x<0)x+=Mod;} 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],(ll)c[i]%Mod*lz[x]%Mod),add(s[i],lz2[x]),add(c[i],lzc[x]); lz[x]=lz2[x]=lzc[x]=0; } void update(int x,int y){ add(lz[x],y); add(lz2[x],(ll)y*lzc[x]%Mod); } void updatec(int x,int y){ add(lzc[x],y); } void update(int l,int r,int x){ if(bel[l]==bel[r]){ for(int i=l;i<=r;i++)add(s[i],(ll)(c[i]+(ll)lzc[bel[l]])%Mod*x%Mod); return; } build(bel[l]),build(bel[r]); for(int i=l;bel[i]==bel[l];i++)add(s[i],(ll)c[i]*x%Mod); for(int i=bel[l]+1;i<bel[r];i++)update(i,x); for(int i=r;bel[i]==bel[r];i--)add(s[i],(ll)c[i]*x%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; } build(bel[l]),build(bel[r]); for(int i=l;bel[i]==bel[l];i++)add(c[i],x); for(int i=bel[l]+1;i<bel[r];i++)updatec(i,x); for(int i=r;bel[i]==bel[r];i--)add(c[i],x); } int qry(int x){ return (s[x]+(ll)c[x]*lz[bel[x]]%Mod+lz2[bel[x]])%Mod; } void prt(){ for(int i=1;i<=n;i++)cout<<s[i]<<" ";cout<<endl; } }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,(ll)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((ll)x*c[pos]%Mod,(ll)y*p[pos]%Mod)); add(c[pos],(ll)p[pos]*z%Mod); add(lz[pos],x); add(lz2[pos],Add(y,(ll)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)); } void prt(int pos,int l,int r){ if(l==r){ cout<<t[pos]<<" "; return; } pushdown(pos); int mid=(l+r)>>1; prt(lson,l,mid);prt(rson,mid+1,r); } }D; int query(int l,int r){ int mtp=(qry(r)-qry(l-1)+Mod)%Mod,tmp=D.query(1,1,n,l,r); return Add(mtp,tmp); } 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("%lld\n",query(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; }