hdu 4578 Transformation

时间:2021-12-23 03:28:17

http://acm.hdu.edu.cn/showproblem.php?pid=4578

题意:1,a,b,c代表在a,b区间的每一个数加上c;2,a,b,c代表在a,b区间的每一个数乘上c; 3,a,b,c代表在a,b区间的每一个数变为c;4,a,b,c是求在a,b区间的每一个数的c次方的和。

先乘后加。

 #include <cstdio>
#include <cstring>
#include <algorithm>
#define maxn 100010
using namespace std; int n,m;
struct node
{
int r,l;
int sum;
int add;
int mul;
int sum2;
int sum3;
}tree[maxn*]; void build(int i,int l,int r)
{
tree[i].l=l;
tree[i].r=r;
tree[i].sum=;
tree[i].add=;
tree[i].mul=;
tree[i].sum2=;
tree[i].sum3=;
if(l==r) return ;
int mid=(l+r)>>;
build(i<<,l,mid);
build(i<<|,mid+,r);
} void mull(int i,int data1,int data)
{
(tree[i].sum*=data1)%=;
tree[i].sum2=tree[i].sum2*data1%*data1%;
tree[i].sum3=tree[i].sum3*data1%*data1%*data1%;
(tree[i].mul*=data1)%=;
(tree[i].add*=data1)%=;
(tree[i].sum3+=((tree[i].r-tree[i].l+)%*(data%*data%*data%)))%=;
(tree[i].sum3+=*data%*tree[i].sum2%)%=;
(tree[i].sum3+=(*data%*data%*tree[i].sum%))%=;
(tree[i].sum2+=(tree[i].r-tree[i].l+)*(data*data%)%)%=;
(tree[i].sum2+=(*data%*tree[i].sum%))%=;
(tree[i].sum+=(tree[i].r-tree[i].l+)%*data%)%=;
(tree[i].add+=data)%=;
}
void down(int i)
{
if(tree[i].l==tree[i].r) return ;
mull(i<<,tree[i].mul,tree[i].add);
mull(i<<|,tree[i].mul,tree[i].add);
tree[i].add=;
tree[i].mul=;
}
void update(int i,int l,int r,int data1,int data)
{
if(tree[i].l==l&&tree[i].r==r)
{
mull(i,data1,data);
return ;
}
down(i);
int mid=(tree[i].l+tree[i].r)>>;
if(r<=mid)
{
update(i<<,l,r,data1,data);
}
else if(l>mid)
{
update(i<<|,l,r,data1,data);
}
else
{
update(i<<,l,mid,data1,data);
update(i<<|,mid+,r,data1,data);
}
tree[i].sum=(tree[i<<].sum+tree[i<<|].sum)%;
tree[i].sum2=(tree[i<<].sum2+tree[i<<|].sum2)%;
tree[i].sum3=(tree[i<<].sum3+tree[i<<|].sum3)%;
} int search1(int i,int l,int r,int ch)
{
if(tree[i].l==l&&tree[i].r==r)
{
if(ch==)
return tree[i].sum;
else if(ch==)
return tree[i].sum2;
else if(ch==)
return tree[i].sum3;
}
down(i);
int mid=(tree[i].l+tree[i].r)>>;
if(r<=mid)
{
return search1(i<<,l,r,ch);
}
else if(l>mid)
{
return search1(i<<|,l,r,ch);
}
else
{
return (search1(i<<,l,mid,ch)+search1(i<<|,mid+,r,ch))%;
}
} int main()
{
while(scanf("%d%d",&n,&m)!=EOF)
{
if(n==&&m==) break;
build(,,n);
for(int i=; i<=m; i++)
{
int x,y,op,c;
scanf("%d%d%d%d",&op,&x,&y,&c);
if(op==)
{
update(,x,y,,c);
}
else if(op==)
{
update(,x,y,c,);
}
else if(op==)
{
update(,x,y,,c);
}
else if(op==)
{
printf("%d\n",search1(,x,y,c)%);
}
}
}
return ;
}