因为脑子抽了外加智商不够而且思路混乱导致错误,求调,关
查看原帖
因为脑子抽了外加智商不够而且思路混乱导致错误,求调,关
369200
Konnyaku_k楼主2025/1/28 16:53

求调,玄关

//#include<windows.h>
#include<cstdlib>
#include<ctime>
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
using namespace std;
long long a[111111];
struct XDS{
	int l;
	int r;
	long long h1;
	long long h2;
	long long h3=1;
};
XDS t[444444];
void jt(int x,int y,int q)
{
	t[q].l=x;
	t[q].r=y;
	if(x==y)
	{
		t[q].h1=a[y];
		return;
	}
	int ban=(x+y)/2;
	jt(x,ban,q*2);
	jt(ban+1,y,q*2+1);
	t[q].h1=t[q*2].h1+t[q*2+1].h1;
}
void down(int q)
{
	t[q*2].h1=t[q*2].h1*t[q].h3;
	t[q*2].h1=t[q*2].h1+t[q].h2*(t[q*2].r-t[q*2].l+1);
	t[q*2].h2=(t[q*2].h2+t[q].h2)*t[q].h3;
	t[q*2].h3=t[q*2].h3*t[q].h3;
	t[q*2+1].h1=t[q*2+1].h1*t[q].h3;
	t[q*2+1].h1=t[q*2+1].h1+t[q].h2*(t[q*2+1].r-t[q*2+1].l+1);
	t[q*2+1].h2=(t[q*2+1].h2+t[q].h2)*t[q].h3;
	t[q*2+1].h3=t[q*2+1].h3*t[q].h3;
	t[q].h2=0;
	t[q].h3=1;
}
void one(int x,int y,long long k,int q)
{
	int ban=(t[q].l+t[q].r)/2;
	if(t[q].l>=x&&t[q].r<=y)
	{
		t[q].h1=t[q].h1*k;
		t[q].h2=t[q].h3*k;
		return;
	}
	down(q);
	if(x<=ban)
	{
		one(x,y,k,q*2);
	}
	if(ban>y)
	{
		one(x,y,k,q*2+1);
	}
	t[q].h1=t[q*2].h1+t[q*2+1].h1;
}
void two(int x,int y,long long k,int q)
{
	int ban=(t[q].l+t[q].r)/2;
	if(t[q].l>=x&&t[q].r<=y)
	{
		t[q].h1=t[q].h1+k*(t[q].r-t[q].l+1);
		t[q].h2=t[q].h2+k;
		return;
	}
	down(q);
	if(x<=ban)
	{
		two(x,y,k,q*2);
	}
	if(ban>y)
	{
		two(x,y,k,q*2+1);
	}
	t[q].h1=t[q*2].h1+t[q*2+1].h1;
}
long long three(int x,int y,int q)
{
	int ban=(t[q].l+t[q].r)/2;
	long long s=0;
	if(t[q].l>=x&&t[q].r<=y)
	{
		return t[q].h1;
	}
	down(q);
	if(x<=ban)
	{
		s=s+three(x,y,q*2);
	}
	if(ban>y)
	{
		s=s+three(x,y,q*2+1);
	}
	return s;
}
int main()
{
	int n,m,p,j,x,y;
	long long k;
	cin>>n>>m>>p;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
	}
	jt(1,n,1);
	for(int i=1;i<=m;i++)
	{
		cin>>j;
		if(j==1)
		{
			cin>>x>>y>>k;
			one(x,y,k,1);
		}
		else if(j==2)
		{
			cin>>x>>y>>k;
			two(x,y,k,1);
		}
		else if(j==3)
		{
			cin>>x>>y;
			cout<<three(x,y,1)<<endl;
		}
	}
	return 0;
}
2025/1/28 16:53
加载中...