Skip to content

Latest commit

 

History

History
34 lines (33 loc) · 589 Bytes

区间修改单点查询 (2).md

File metadata and controls

34 lines (33 loc) · 589 Bytes
tags title created modified
Code
区间修改单点查询
2022-09-02T13:07:02.348Z
2022-09-02T13:07:30.131Z

区间修改单点查询

typedef long long ll;
int n;
int c1[100010];
int c2[100010];
void add(int p, int x)
{
	for (int i = p; i <= n; i += i & -i)
		c1[i] += x, c2[i] += p * x;
}
void range_add(int l, int r, int x)
{
	add(l, x), add(r + 1, -x);
}
int ask(int p)
{
	int res = 0;
	for (int i = p; i; i -= i & -i)
		res += (p + 1) * c1[i] - c2[i];
	return res;
}
int range_ask(int l, int r)
{
	return ask(r) - ask(l - 1);
}