玄4关,求调
查看原帖
玄4关,求调
1087233
WuJiaNuo19楼主2024/12/24 22:23

9pts

using namespace std;
#define int long long
#define ls rt*2
#define rs rt*2+1
#define mid (l+r)/2
#define lson rt*2,l,mid
#define rson rt*2+1,mid+1,r
const int N = 8e5+5;
int tree[N],fs[N],fg[N],val[N/4];
int n,m;
void pushdown(int rt,int l,int r)
{
	tree[rt]+=(r-l+1)*(r-l)/2*fg[rt];
	tree[rt]+=(r-l+1)*fs[rt];
	if(l!=r)
	{
		fs[ls]+=fs[rt];
		fs[rs]+=fs[rt];
		fs[rs]+=(mid-l+1)*fg[rt];
		fg[ls]+=fg[rt];
		fg[rs]+=fg[rt];
	}
	fs[rt] = 0;
	fg[rt] = 0;
	return ;
}
void pushup(int rt,int l,int r)
{
	if(l!=r)
	{
		pushdown(lson);
		pushdown(rson);
	}
	tree[rt] = tree[ls]+tree[rs];
	return ;
}
void build(int rt,int l,int r)
{
	if(l==r)
	{
		tree[rt] = val[l];
		return ;
	}
	build(lson);
	build(rson);
	pushup(rt,l,r);
	return ;
}
int query(int rt,int l,int r,int L,int R)
{
	pushdown(rt,l,r);
	if(L<=l and r<=R)
	{
		return tree[rt];
	}
	if(L<=mid)
	{
		return query(lson,L,R);
	}
	return query(rson,L,R);
}
void update(int rt,int l,int r,int L,int R,int k,int d)
{
	pushdown(rt,l,r);
	if(l>=L and r<=R)
	{
		fs[rt]=k;
		fg[rt]=d;
		return ;
	}
	if(L<=mid)
	{
		update(lson,L,R,k,d);
	}
	if(R>mid)
	{
		int x = mid-L+1;
		if(x<0)
		{
			x = 0;
		} 
		update(rson,L,R,k,d);
	}
	pushup(rt,l,r);
}
signed main()
{
	cin>>n>>m;
	int opt,l,r,k,d,p;
	for(int i=1;i<=n;++i)
	{
		cin>>val[i];
	}
	build(1,1,n);
	while(m--)
	{
		cin>>opt;
		if(opt==1)
		{
			cin>>l>>r>>k>>d;
			update(1,1,n,l,r,k,d);
		}
		else
		{
			cin>>p;
			cout<<query(1,1,n,p,p)<<"\n";
		}
	}
	return 0;
}
2024/12/24 22:23
加载中...