版本比较
论如何在 hyzx 活下去
正文
增加 16 行删除 37 行
11234567891011121314151617181920212223242526275678910111230313233343536131415161718192021383940414222234424```cpp line-numbers```cpp#include <bits/stdc++.h>using namespace std;typedef long long ll;const int N=1e5+5;ll n,q,mod,a[N];struct Seg {ll l,r,sum,add,mul;}t[N<<2];ll read() {/*...*/}void push_up(int x) {t[x].sum=(t[x*2].sum+t[x*2+1].sum)%mod;}void push_down(int x,int y) { int len=t[y].r-t[y].l+1; t[y].sum=(t[y].sum*t[x].mul+t[x].add*len)%mod; t[y].mul=t[y].mul*t[x].mul%mod; t[y].add=(t[y].add*t[x].mul+t[x].add)%mod;}void build(int x,int l,int r) { t[x]={l,r,0,0,1}; if(l==r) {t[x].sum=a[l]; return;} int mid=(l+r)/2; build(x*2,l,mid); build(x*2+1,mid+1,r); push_up(x);}ll query(int x,int l,int r) { if(l<=t[x].l && t[x].r<=r) return t[x].sum; push_down(x,x*2); push_down(x,x*2+1); t[x].add=0; t[x].mul=1; int mid=(t[x].l+t[x].r)/2; ll res=0; if(l<=mid) res+=query(x*2,l,r); if(r>mid) res+=query(x*2+1,l,r);const int N=5e5+5;ll n,q,a[N],t[N];void update(int x,int k) {for(;x<=n;x+=x&-x) t[x]+=k;}ll query(int x) { ll res=0; for(;x;x-=x&-x) res+=t[x]; return res;}void update(int x,int l,int r,int k,int op) { if(l<=t[x].l && t[x].r<=r) { int len=t[x].r-t[x].l+1; if(op==1) { t[x].add=t[x].add*k%mod; t[x].sum=t[x].sum*k%mod; t[x].mul=t[x].mul*k%mod; } else {t[x].sum=(t[x].sum+k*len)%mod; t[x].add=(t[x].add+k)%mod;} return;int main() { cin>>n>>q; for(int i=1;i<=n;i++) cin>>a[i]; for(int i=1;i<=n;i++) update(i,a[i]); for(int op,x,y;q;q--) { cin>>op>>x>>y; if(op==1) update(x,y); else cout<<query(y)-query(x-1)<<'\n'; } push_down(x,x*2); push_down(x,x*2+1); t[x].add=0; t[x].mul=1; int mid=(t[x].l+t[x].r)/2; if(l<=mid) update(x*2,l,r,k,op); if(r>mid) update(x*2+1,l,r,k,op); push_up(x); return 0;}int main() {/*...*/}``````