推的式子:SSp=(n+1)i=1∑pai−i=1∑pai×i
#include <bits/stdc++.h>
#define re long long
using namespace std;
typedef long long LL;
const int N = 1e5 + 10;
LL n, m, a[N], c0[N], c1[N];
inline LL lowbit(LL x) { return x & -x; }
inline void add(LL *c, LL x, LL k)
{
while (x <= n)
{
c[x] += k;
x += lowbit(x);
}
}
inline LL query(LL *c, LL x)
{
LL res = 0;
while (x > 0)
{
res += c[x];
x -= lowbit(x);
}
return res;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
cin >> n >> m;
for (re i = 1; i <= n; i ++)
{
cin >> a[i];
add(c0, i, a[i]);
add(c1, i, a[i] * i);
}
while (m --)
{
string s;
LL x, k;
cin >> s;
if (s[0] == 'Q')
{
cin >> x;
cout << (n + 1) * query(c0, x) - query(c1, x) << "\n";
}
else
{
cin >> x >> k;
add(c0, x, k - a[x]);
add(c1, x, (k - a[x]) * x);
a[x] = k;
}
}
return 0;
}