题目描述
blablabla
样例
blablabla
算法1
(暴力枚举) $O(n^2)$
blablabla
时间复杂度
参考文献
C++ 代码
blablabla
算法2
(暴力枚举) $O(n^2)$
blablabla
时间复杂度
参考文献
C++ 代码
#include<iostream>
using namespace std;
typedef long long LL;
const int N = 1e5 + 10;
int n, m;
LL a[N], tr[N], tri[N];
int lowbit(int x)
{
return x & -x;
}
void add(int x, LL c)
{
for (int i = x; i <= n; i += lowbit(i))
{
tr[i] += c;
tri[i] += c * x;
}
}
LL sum(int x)
{
LL res = 0;
for (int i = x; i; i -= lowbit(i))
res += tr[i] * (x + 1) - tri[i];
return res;
}
int main()
{
cin >> n >> m;
for (int i = 1; i <= n; i ++) cin >> a[i];
for (int i = 1; i <= n; i ++) add(i, a[i] - a[i - 1]);
while(m --)
{
char op[2];
int l, r, c;
scanf("%s%d%d", op, &l, &r);
if(*op == 'Q')
{
cout << sum(r) - sum(l - 1) << endl;
}
else
{
scanf("%d", &c);
add(l, c);
add(r + 1, -c);
}
}
return 0;
}