Icebound

icebound-area

test test test

test 仅仅是用来测试的

  • 无论你在什么时候开始,重要的是开始以后就不要停止。——BY zrt

 

 

#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
const int size=100000;
int n,m,a[size+10];
struct stree
{
	int l,r;
	long long sum,add;
}tr[size*4+10];
inline void build(int p,int l,int r)
{
	tr[p].l=l,tr[p].r=r;
	if(l==r){tr[p].sum=a[l];return;}
	int mid=(l+r)/2;
	build(p*2,l,mid);
	build(p*2+1,mid+1,r);
	tr[p].sum=tr[p*2].sum+tr[p*2+1].sum;
}
inline void speard(int p)
{
	if(tr[p].add)
	{
		tr[p*2].sum+=tr[p].add*(tr[p*2].r-tr[p*2].l+1);
		tr[p*2+1].sum+=tr[p].add*(tr[p*2+1].r-tr[p*2+1].l+1);
		tr[p*2].add+=tr[p].add;
		tr[p*2+1].add+=tr[p].add;
		tr[p].add=0;
	}
}
inline void change(int p,int l,int r,int x)
{
	if(l<=tr[p].l&&r>=tr[p].r)
	{
		tr[p].sum+=(long long)x*(tr[p].r-tr[p].l+1);//此处也可若修改则为= 
		tr[p].add+=x;
		return;
	}
	speard(p);
	int mid=(tr[p].l+tr[p].r)/2;
	if(l<=mid)change(p*2,l,r,x);
	if(r>mid)change(p*2+1,l,r,x);//r>=mid+1
	tr[p].sum=tr[p*2].sum+tr[p*2+1].sum;
}
inline long long ask(int p,int l,int r)
{
	if(l<=tr[p].l&&r>=tr[p].r)return tr[p].sum;
	speard(p);
	int mid=(tr[p].l+tr[p].r)/2;
	long long ans=0;
	if(l<=mid)ans+=ask(p*2,l,r);
	if(r>mid)ans+=ask(p*2+1,l,r);
	return ans;
}
int main()
{
	cin>>n>>m;
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	build(1,1,n);
	while(m--)
	{
		char op[2]; int x,y,z;
		scanf("%s%d%d",op,&x,&y);
		if(op[0]=='C')
		{
			scanf("%d",&z);
			change(1,x,y,z);
		}
		else printf("%I64d\n",ask(1,x,y));
	}
}
  1. zrt说道:

    test comment .
    不错哦~

  2. Wilbert说道:

    While to a different pine crew member it could cause a possible collision as an example a method for starters pine crew member maybe sensible.

  3. Fantastic information, better still to discover your blog that
    has a fantastic layout. Effectively done