题目:
分析:
线段树
代码:
// Problem: F - Two Sequence Queries
// Contest: AtCoder - SuntoryProgrammingContest2024(AtCoder Beginner Contest 357)
// URL: https://atcoder.jp/contests/abc357/tasks/abc357_f
// Memory Limit: 1024 MB
// Time Limit: 5000 ms
//
// Powered by CP Editor (https://cpeditor.org)
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N = 2e6+5;
const int mod=998244353;
int n,q;
int a[N],b[N];
int taga[N],tagb[N];
int sum[N],suma[N],sumb[N];
void addtag(int p,int pl,int pr,int d,int k){
if(k==1){
(suma[p]+=1ll*d*(pr-pl+1)%mod)%=mod;
(sum[p]+=1ll*sumb[p]*d%mod)%=mod;
(taga[p]+=d)%=mod;
}
else{
(sumb[p]+=1ll*d*(pr-pl+1)%mod)%=mod;
(sum[p]+=1ll*suma[p]*d%mod)%=mod;
(tagb[p]+=d)%=mod;
}
}
void pushup(int p){
(suma[p]=(suma[p*2]+suma[p*2+1])%mod)%=mod;
(sumb[p]=(sumb[p*2]+sumb[p*2+1])%mod)%=mod;
(sum[p]=(sum[p*2]+sum[p*2+1])%mod)%=mod;
}
void pushdown(int p,int pl,int pr){
int mid=(pl+pr)/2;
if(taga[p]){
addtag(p*2,pl,mid,taga[p],1);
addtag(p*2+1,mid+1,pr,taga[p],1);
taga[p]=0;
}
if(tagb[p]){
addtag(p*2,pl,mid,tagb[p],2);
addtag(p*2+1,mid+1,pr,tagb[p],2);
tagb[p]=0;
}
}
void build(int p,int pl,int pr){
if(pl==pr){
suma[p]=a[pl]%mod;
sumb[p]=b[pl]%mod;
sum[p]=1ll*a[pl]*b[pl]%mod;
taga[p]=tagb[p]=0;
return;
}
int mid=(pl+pr)/2;
build(p*2,pl,mid);
build(p*2+1,mid+1,pr);
pushup(p);
return;
}
void update(int l,int r,int p,int pl,int pr,int d,int k){
if(l<=pl&&pr<=r){
addtag(p,pl,pr,d,k);
return;
}
int mid=(pl+pr)/2;
pushdown(p,pl,pr);
if(l<=mid){
update(l,r,p*2,pl,mid,d,k);
}
if(r>mid){
update(l,r,p*2+1,mid+1,pr,d,k);
}
pushup(p);
return;
}
int query(int l,int r,int p,int pl,int pr){
if(l<=pl&&pr<=r){
return sum[p];
}
int mid=(pl+pr)/2;
pushdown(p,pl,pr);
int ans=0;
if(l<=mid){
(ans+=query(l,r,p*2,pl,mid))%=mod;
}
if(r>mid){
(ans+=query(l,r,p*2+1,mid+1,pr))%=mod;
}
return ans;
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
cin>>n>>q;
for(int i=1;i<=n;i++){
cin>>a[i];
}
for(int i=1;i<=n;i++){
cin>>b[i];
}
build(1,1,n);
while(q--){
int op,l,r,x;
cin>>op;
if(op==1){
cin>>l>>r>>x;
update(l,r,1,1,n,x,1);
}
else if(op==2){
cin>>l>>r>>x;
update(l,r,1,1,n,x,2);
}
else if(op==3){
cin>>l>>r;
cout<<query(l,r,1,1,n)<<"\n";
}
}
return 0;
}