难绷,MLE
查看原帖
难绷,MLE
769006
crzcqh楼主2025/7/26 22:13
#include<bits/stdc++.h>
#define int long long
#define lp p<<1
#define rp p<<1|1 
using namespace std;
const int N=3e5+5;
int n,m,q;
int val[N],x[N];
set<int> s;
struct SegmentTree{
	int l,r,sum,dis,val,dtag,vtag;
}tree[N<<4];
inline void pushup(int p){
	tree[p].dis=tree[lp].dis+tree[rp].dis;
	tree[p].val=tree[lp].val;
	tree[p].sum=tree[lp].sum+tree[rp].sum;
}
inline void pushdown(int p){
	if(!tree[p].dtag&&!tree[p].vtag)
		return;
	int dis=tree[p].dtag,val=tree[p].vtag;
	if(val)
		tree[lp].val=val,tree[rp].val=val;
	tree[lp].dis-=(tree[lp].r-tree[lp].l+1)*dis;
	tree[rp].dis-=(tree[rp].r-tree[rp].l+1)*dis;
	tree[lp].sum=tree[lp].val*tree[lp].dis;
	tree[rp].sum=tree[rp].val*tree[rp].dis;
	tree[lp].dtag+=dis,tree[rp].dtag+=dis;
	if(val)
		tree[lp].vtag=tree[rp].vtag=val;
	tree[p].dtag=tree[p].vtag=0;
}
void build(int p,int l,int r){
	tree[p].l=l,tree[p].r=r;
	if(l==r){
		auto nxt=s.lower_bound(l);
		if((*nxt)==l)
			return;
		auto now=nxt;
		now--;
		tree[p].val=val[*now];
		tree[p].dis=(*nxt)-l;
		tree[p].sum=tree[p].val*tree[p].dis;
		return;
	}
	int mid=l+r>>1;
	build(lp,l,mid);
	build(rp,mid+1,r);
	pushup(p);
}
void D_updata(int p,int l,int r,int d){
	if(tree[p].l>=l&&tree[p].r<=r){
		tree[p].dis-=(tree[p].r-tree[p].l+1)*d;
		tree[p].sum=tree[p].dis*tree[p].val;
		tree[p].dtag+=d;
		return;
	}
	pushdown(p);
	int mid=tree[p].l+tree[p].r>>1;
	if(l<=mid)
		D_updata(lp,l,r,d);
	if(r>mid)
		D_updata(rp,l,r,d);
	pushup(p);
}
void V_updata(int p,int l,int r,int v){
	if(tree[p].l>=l&&tree[p].r<=r){
		tree[p].val=v;
		tree[p].vtag=v;
		tree[p].sum=tree[p].dis*tree[p].val;
		return;
	}
	pushdown(p);
	int mid=tree[p].l+tree[p].r>>1;
	if(l<=mid)
		V_updata(lp,l,r,v);
	if(r>mid)
		V_updata(rp,l,r,v);
	pushup(p);
}
int query(int p,int l,int r){
	if(tree[p].l>=l&&tree[p].r<=r)
		return tree[p].sum;
	pushdown(p);
	int mid=tree[p].l+tree[p].r>>1;
	int ans=0;
	if(l<=mid)
		ans+=query(lp,l,r);
	if(r>mid)
		ans+=query(rp,l,r);
	return ans; 
}
void modify(int p,int x){
	if(tree[p].l==tree[p].r){
		tree[p].dis=tree[p].val=tree[p].dtag=tree[p].vtag=tree[p].sum=0;
		return;
	}
	int mid=tree[p].l+tree[p].r>>1;
	if(x<=mid)
		modify(lp,x);
	else
		modify(rp,x);
	pushup(p); 
}
signed main(){
	ios::sync_with_stdio(0);
	cin.tie(0),cout.tie(0);
	cin>>n>>m>>q;
	for(int i=1;i<=m;i++)
		cin>>x[i],s.insert(x[i]);
	for(int i=1;i<=m;i++)
		cin>>val[x[i]];
	build(1,1,n);
	while(q--){
		int op,l,r;
		cin>>op>>l>>r;
		if(op==1){
			s.insert(l);
			val[l]=r;
			auto pos=s.find(l);
			auto pre=pos,nxt=pos;
			pre--,nxt++;
			int prex=*pre,nxtx=*nxt;
			if(prex+1<l)
				D_updata(1,prex+1,l-1,(nxtx-l));
			if(l+1<nxtx)
				V_updata(1,l+1,nxtx-1,r);
			modify(1,l);
		}
		else cout<<query(1,l,r)<<endl;
	}
	return 0;
}


有没有大佬能讲一下为啥 MLE

2025/7/26 22:13
加载中...