题意:
区间加法,区间求和。
裸模板。
似乎不会写了...
注意加法里的v题里说<=1e7,然而似乎要开LL才能过。
#include <cstdio>
typedef unsigned long long ULL;
const int maxn = 100005;
int n;
ULL addv[maxn << 2], tr[maxn << 2];
inline int iread() {
int f = 1, x = 0; char ch = getchar();
for(; ch < '0' || ch > '9'; ch = getchar()) f = ch == '-' ? -1 : 1;
for(; ch >= '0' && ch <= '9'; ch = getchar()) x = x * 10 + ch - '0';
return f * x;
}
inline void pushup(int p) {
tr[p] = tr[p << 1] + tr[p << 1 | 1];
}
inline void pushdown(int p, int l, int mid, int r) {
if(addv[p]) {
addv[p << 1] += addv[p]; addv[p << 1 | 1] += addv[p];
tr[p << 1] += (mid - l + 1) * addv[p]; tr[p << 1 | 1] += (r - mid) * addv[p];
addv[p] = 0;
}
}
inline void add(int p, int l, int r, int x, int y, ULL c) {
if(x <= l && r <= y) {
tr[p] += (r - l + 1) * c; addv[p] += c;
return;
}
int mid = l + r >> 1;
pushdown(p, l, mid, r);
if(x <= mid) add(p << 1, l, mid, x, y, c);
if(y > mid) add(p << 1 | 1, mid + 1, r, x, y, c);
pushup(p);
}
inline ULL query(int p, int l, int r, int x, int y) {
if(x <= l && r <= y)
return tr[p];
int mid = l + r >> 1;
pushdown(p, l, mid, r);
ULL ans = 0;
if(x <= mid) ans += query(p << 1, l, mid, x, y);
if(y > mid) ans += query(p << 1 | 1, mid + 1, r, x, y);
return ans;
}
int main() {
int T = iread();
while(T--) {
n = iread();
for(int i = n << 2; i >= 0; i--) tr[i] = addv[i] = 0;
int m = iread();
while(m--) {
int opt = iread(), x = iread(), y = iread();
if(opt == 0) {
ULL c; scanf("%llu", &c); add(1, 1, n, x, y, c);
}
else printf("%llu\n", query(1, 1, n, x, y));
}
}
return 0;
}