# bzoj 4499: 线性函数 线段树

【想说的话】

【题解】

【代码】

#include<bits/stdc++.h>

#define mod 1000000007
#define MAXN 200020

typedef long long ll;

using namespace std;

inline ll rd(){
ll x=0,y=1;char c=getchar();
while(c<'0' || c>'9'){if(c=='-')y=-y;c=getchar();}
while(c>='0'&&c<='9')x=x*10+c-'0',c=getchar();
return x*y;
}

struct node{
ll k,b;
friend node operator + (node x,node y){
node ret;
ret.k=(x.k*y.k)%mod;
ret.b=(y.k*x.b%mod+y.b)%mod;
return ret;
}
};

struct node1{
int l,r;
node line;
}tree[MAXN*4];

int n,m;
node a[MAXN];

void build(int x,int l,int r){
tree[x].l=l;
tree[x].r=r;
if(l==r){
tree[x].line=a[l];
return;
}
int mid=(l+r)/2;
build(x*2,l,mid);
build(x*2+1,mid+1,r);
tree[x].line=tree[x*2].line+tree[x*2+1].line;
}

node query(int x,int l,int r){
if(tree[x].l==l && tree[x].r==r)return tree[x].line;
int mid=(tree[x].l+tree[x].r)/2;
if(r<=mid)return query(x*2,l,r);
else if(l>mid)return query(x*2+1,l,r);
else return query(x*2,l,mid)+query(x*2+1,mid+1,r);
}

void update(int x,int y,node k){
if(tree[x].l==tree[x].r){
tree[x].line=k;
return;
}
int mid=(tree[x].l+tree[x].r)/2;
if(y<=mid)update(x*2,y,k);
else update(x*2+1,y,k);
tree[x].line=tree[x*2].line+tree[x*2+1].line;
}

int main(){
n=rd(),m=rd();
for(int i=1; i<=n; i++)a[i].k=rd()%mod,a[i].b=rd()%mod;
build(1,1,n);
while(m--){
char c[2];
ll x,y,z;
scanf("%s",c);
if(c[0]=='Q'){
x=rd(),y=rd(),z=rd();
node ret=query(1,x,y);
printf("%lld\n",(ret.k*z%mod+ret.b)%mod);
}
else{
x=rd(),y=rd(),z=rd();
node ret;
ret.k=y%mod,ret.b=z%mod;
update(1,x,ret);
}
}

return 0;
}