0pts求调
查看原帖
0pts求调
773998
RisefromtheDP楼主2024/8/21 17:18
#include<bits/stdc++.h>
#define int long long
using namespace std;
struct _{
	int l,r,num,lazy_j,lazy_c;
}t[400005];
int n,q,m,x,y,k,a[100005];
void build(int l,int r,int xb){
	t[xb].l=l;
	t[xb].r=r;
	t[xb].lazy_c=1;
	t[xb].lazy_j=0;
	if(l==r){
		t[xb].num=a[l]%m;
		return;
	}
	int mid=(l+r)/2;
	build(l,mid,xb*2);
	build(mid+1,r,xb*2+1);
	t[xb].num=(t[xb*2].num+t[xb*2+1].num)%m;
}
void push_down(int xb){
	t[xb*2].num=(t[xb*2].num*t[xb].lazy_c+(t[xb*2].r-t[xb*2].l+1)*t[xb].lazy_j)%m;
	t[xb*2+1].num=(t[xb*2+1].num*t[xb].lazy_c+(t[xb*2+1].r-t[xb*2+1].l+1)*t[xb].lazy_j)%m;
	t[xb*2].lazy_c=(t[xb*2].lazy_c*t[xb].lazy_c)%m;
	t[xb*2+1].lazy_c=(t[xb*2+1].lazy_c*t[xb].lazy_c)%m;
	t[xb*2].lazy_j=(t[xb*2].lazy_j*t[xb].lazy_c+t[xb].lazy_j)%m;
	t[xb*2+1].lazy_j=(t[xb*2+1].lazy_j*t[xb].lazy_c+t[xb].lazy_j)%m;
	t[xb].lazy_c=1;
	t[xb].lazy_j=0;
}
void change_c(int xb){
	if(x<=t[xb].l&&y>=t[xb].r){
		t[xb].num=t[xb].num*k%m;
		t[xb].lazy_c=t[xb].lazy_c*k%m;
		t[xb].lazy_j=t[xb].lazy_j*k%m;
		return;
	}
	push_down(xb);
	int mid=(t[xb].l+t[xb].r)/2;
	if(x<=mid){
		change_c(xb*2);
	}
	if(y>mid){
		change_c(xb*2+1);
	}
	t[xb].num=(t[xb*2].num+t[xb*2+1].num)%m;
}
void change_j(int xb){
	if(x<=t[xb].l&&y>=t[xb].r){
		t[xb].num=(t[xb].num+(t[xb].r-t[xb].l+1)*k)%m;
		t[xb].lazy_j=(t[xb].lazy_j+k)%m;
		return;
	}
	push_down(xb);
	int mid=(t[xb].l+t[xb].r)/2;
	if(x<=mid){
		change_j(xb*2);
	}
	if(y>mid){
		change_j(xb*2+1);
	}
	t[xb].num=(t[xb*2].num+t[xb*2+1].num)%m;
}
int query(int xb){
	if(x<=t[xb].l&&y>=t[xb].r){
		return t[xb].num;
	}
	int res=0,mid=(t[xb].l+t[xb].r)/2;
	if(x<=mid){
		res+=query(xb*2);
	}
	if(y>mid){
		res+=query(xb*2+1);
	}
	return res%m;
}
signed main(){
	ios::sync_with_stdio(false);
	cin>>n>>q>>m;
	for(int i=1;i<=n;i++){
		cin>>a[i];
	}
	build(1,n,1);
	for(int i=1;i<=q;i++){
		int op;
		cin>>op;
		if(op==1){
			cin>>x>>y>>k;
			change_c(1);
		}
		if(op==2){
			cin>>x>>y>>k;
			change_j(1);
		}
		if(op==3){
			cin>>x>>y;
			cout<<query(1)<<endl;
		}
	}
	return 0;
}

2024/8/21 17:18
加载中...