题目链接:传送门
求
带单点修改
把式子拆开
求
维护一个区间和和一个区间就好了
/**
* @Date: 2019-07-11T15:55:17+08:00
* @Email: 2743292121@qqssssssssssssssssssssssssssssssssssssssssssscom
* @Last modified time: 2019-07-11T15:55:54+08:00
*/
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <complex>
#include <algorithm>
#include <climits>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <iomanip>
#define
#define
using namespace std;
typedef long long ll;
struct node {
int l, r; ll w, ww;
}tree[A];
int n, m; ll a[A];
void up(int k) {
tree[k].w = tree[k << 1].w + tree[k << 1 | 1].w;
tree[k].ww = tree[k << 1].ww + tree[k << 1 | 1].ww;
}
void build(int k, int l, int r) {
tree[k].l = l; tree[k].r = r;
if (l == r) {
tree[k].w = a[l];
tree[k].ww = a[l] * l;
return;
}
int m = (l + r) >> 1;
build(k << 1, l, m);
build(k << 1 | 1, m + 1, r);
up(k);
}
void change(int k, int val, int pos) {
if (tree[k].l == tree[k].r) {
tree[k].w += val;
tree[k].ww += val * tree[k].l;
return;
}
int m = (tree[k].l + tree[k].r) >> 1;
if (pos <= m) change(k << 1, val, pos);
else change(k << 1 | 1, val, pos);
up(k);
}
ll askw(int k, int l, int r) {
if (tree[k].l >= l and tree[k].r <= r) return tree[k].w;
int m = (tree[k].l + tree[k].r) >> 1; ll ans = 0;
if (l <= m) ans += askw(k << 1, l, r);
if (r > m) ans += askw(k << 1 | 1, l, r);
return ans;
}
ll askww(int k, int l, int r) {
if (tree[k].l >= l and tree[k].r <= r) return tree[k].ww;
int m = (tree[k].l + tree[k].r) >> 1; ll ans = 0;
if (l <= m) ans += askww(k << 1, l, r);
if (r > m) ans += askww(k << 1 | 1, l, r);
return ans;
}
int main(int argc, char const *argv[]) {
freopen("overwatch.in", "r", stdin); freopen("overwatch.out", "w", stdout);
cin >> n >> m;
for (int i = 1; i <= n; i++) cin >> a[i];
build(1, 1, n);
while (m--) {
int opt, x, s; cin >> opt;
if (opt == 1) {
cin >> x >> s;
change(1, s, x);
}
else {
cin >> x >> s;
cout << askw(1, x, s) * s - askww(1, x, s) + askw(1, x, s) << endl;
}
}
return 0;
}
/*
5 3
2 4 1 3 5
2 2 4
1 2 3
2 2 4
*/