示例#1
0
文件: 3468.c 项目: GuidoPaul/ACM
void build(int L, int R, int p) {
	tree[p].L = L;
	tree[p].R = R;
	tree[p].mark = 0;
	if (L == R) {
		tree[p].sum = data[L];
		return ;
	}
	int mid = (L + R) >> 1;
	build(L, mid, p << 1);
	build(mid + 1, R, p << 1 | 1);
	PushUP(p);
}
void Build(int l,int r,int rt)
{
    add[rt]=0;
    if(l==r)
    {
        scanf("%I64d",&sum[rt]);
        return;
    }
    int m=(l+r)>>1;
    Build(lson);
    Build(rson);
    PushUP(rt);
}
示例#3
0
文件: 3468.c 项目: GuidoPaul/ACM
void update(int L, int R, int c, int p) {
	if (L <= tree[p].L && R >= tree[p].R) {
		tree[p].mark += c;
		tree[p].sum += (long long)c * (tree[p].R - tree[p].L + 1);
		return ;
	}
	PushDown(p);
	int mid = (tree[p].L + tree[p].R) >> 1;
	if (mid >= R) update(L, R, c, p << 1);
	else if (mid + 1 <= L) update(L, R, c, p << 1 | 1);
	else {
		update(L, mid, c, p << 1);
		update(mid + 1, R, c, p << 1 | 1);
	}
	PushUP(p);
}
void Update(int L,int R,int c,int l,int r,int rt)
{
    if(L<=l&&R>=r)
    {
        add[rt]+=c;
        sum[rt]+=(LL)c*(r-l+1);
        return;
    }
    PushDown(rt,r-l+1);
    int m=(l+r)>>1;
    if(L<=m)
        Update(L,R,c,lson);
    if(R>m)
        Update(L,R,c,rson);
    PushUP(rt);
}
示例#5
0
文件: 1698.c 项目: GuidoPaul/ACM
void update(int L, int R, int c, int p) {
	if(L <= tree[p].L && R >= tree[p].R) {
		tree[p].mark = c;
		tree[p].sum = (tree[p].R - tree[p].L + 1) * c;
		return ;
	}
	PushDown(p);
	int mid = (tree[p].R + tree[p].L) >> 1;
	if(mid >= R) {
		update(L, R, c, p << 1);
	} else if(mid + 1 <= L) {
		update(L, R, c, p << 1 | 1);
	} else {
		update(L, mid, c, p << 1);
		update(mid + 1, R, c, p << 1 | 1);
	}
	PushUP(p);
}