样例过但 0pts 求助
查看原帖
样例过但 0pts 求助
603732
Traitorous_X楼主2022/11/8 13:44

RT 板子是从我AC的 P3372 上粘下来的 求调教

#include<bits/stdc++.h>
using namespace std;
#define rep(I,N,M) for(int I=N;I<=M;++I)
#define N 100005
#define Root 1
#define ll long long // are you a long
inline int read(void){
	int s=0;char c=getchar();
	while(!isdigit(c)) c=getchar();
	while(isdigit(c)){s= (s<<3) + (s<<1) + (c^48); c=getchar();}
	return s;
}

struct SegmentTree{
	ll l,r;
	ll dat,add,mul;
	#define l(x) tree[x].l
	#define r(x) tree[x].r
	#define dat(x) tree[x].dat
	#define add(x) tree[x].add
	#define mul(x) tree[x].mul
} tree[N*4];

ll n,m,p1,temp[N];

void build_tree(ll p,ll l,ll r){
	l(p) = l; r(p) = r;
	if (l == r) { dat(p) = temp[l]; return;}
	ll mid = (l + r) >> 1;
	build_tree(p<<1, l, mid);
	build_tree(p<<1|1, mid+1, r);
	dat(p) = dat(p<<1) + dat(p<<1|1);//update storage
}

void spread_note(ll p){
	if(add(p)){
		dat(p<<1) += add(p) * (r(p*2) - l(p*2) + 1);
		dat(p<<1|1) += add(p) * (r(p*2+1) - l(p*2+1) + 1);
		add(p<<1) += add(p);
		add(p<<1|1) += add(p);
		add(p) = 0;
	}
	if(mul(p)){
		dat(p<<1) *= mul(p);
		dat(p<<1|1) *= mul(p);
		mul(p<<1) *= mul(p);
		mul(p<<1|1) *= mul(p);
		mul(p) = 1;	
	}
}

void sectional_target_tree(ll p,ll l,ll r,ll k,ll type){
	if(type==1){
		if(l(p) >= l && r(p) <= r){
			dat(p) *= k;
			dat(p) %= p1;
			mul(p) *= k;
			return;
		}
	}
	else{
		if(l(p) >= l && r(p) <= r){
			dat(p) += k * (r(p) - l(p) + 1);
			dat(p) %= p1; 
			add(p) += k;
			return;
		}
	}
	spread_note(p);
	ll mid = (l(p) + r(p)) >> 1;
	if (l <= mid) sectional_target_tree(p<<1, l, r, k, type);
	if (r > mid) sectional_target_tree(p<<1|1, l, r, k, type);
	dat(p) = dat(p<<1) + dat(p<<1|1);
	dat(p) %= p1;
}

ll sectional_ask_tree(ll p,ll l,ll r){
	if(l(p) >= l && r(p) <= r) return dat(p);
	spread_note(p);
	ll mid = (l(p) + r(p)) >> 1;
	ll val = 0;
	if (l <= mid) val += sectional_ask_tree(p<<1,l,r);
	if (r > mid) val += sectional_ask_tree(p<<1|1,l,r);
	return val % p1;
}

int main(){
	n=read();m=read();p1=read();
//	if(p1!=571373){cout<<"YOU FOOL";exit(-1);}
	memset(tree,0,sizeof(tree));
	rep(i,1,n) temp[i]=read();
	rep(i,1,4*N-1) mul(i)=1;
	build_tree(Root,1,n);
	rep(i,1,m){
		ll det=read(),x=read(),y=read();
		if(det!=3){
			ll k=read();
			sectional_target_tree(Root,x,y,k,det);
	}
		if(det==3) printf("%lld\n",sectional_ask_tree(Root,x,y) % p1);
	}
	return 0;
}

HELP

2022/11/8 13:44
加载中...