求助大佬
查看原帖
求助大佬
281360
LSG_waterf楼主2020/9/7 23:49
#include<bits/stdc++.h>
#define int unsigned long long
#define lowbit(x) x&(-x)
using namespace std;
void read(int &x)
{
	char ch=getchar();x=0;int sgn=1;
	while(ch>'9'||ch<'0') {if(ch=='-') sgn=-1;ch=getchar();}
	while(ch>='0'&&ch<='9') x=(x<<3)+(x<<1)+ch-48,ch=getchar();
	x*=sgn;
}
int c1[500010],c2[500010],a,b,c,u,v,n,m,k,s,t;
void up1(int x,int y)
{
	while(x<=n)
	{
		c1[x]+=y;
		x+=lowbit(x);
	}
}
void up2(int x,int y)
{
	while(x<=n)
	{
		c2[x]+=y;
		x+=lowbit(x);
	}
}
int sum1(int x)
{
	int res=0;
	while(x>0)
	{
		res+=c1[x];
		x-=lowbit(x);
	}
	return res;
}
int sum2(int x)
{
	int res=0;
	while(x>0)
	{
		res+=c2[x];
		x-=lowbit(x);
	}
	return res;
}
signed main()
{
	read(n);read(m);
	for(int i=1;i<=n;i++)
	{
		read(k);
		up1(i,k);up2(i,k);
	}
	for(int i=1;i<=m;i++)
	{
		read(a);
		if(a==1)
		{
			read(s);read(t);read(c);
			up1(s,c);up2(t,c);
		}
		if(a==2)
		{
			read(u);read(v);
			printf("%d\n",sum1(v)-sum2(u-1));
		}
	}
	return 0;
}

树状数组的第二个模板A了,为什么放这里样例都过不了??求助!!!!!

2020/9/7 23:49
加载中...