题目链接:http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DSL_2_E
题意:区间加减查询
solution:
#include <bits/stdc++.h>
using namespace std;
int n, m, a[100005], c[100005];
int lowbit(int x)
{
return x & (-x);
}
void updata(int i, int k)
{
while (i <= n){
c[i] += k;
i += lowbit(i);
}
}
int getsum(int i)
{
int res = 0;
while(i > 0){
res += c[i];
i -= lowbit(i);
}
return res;
}
int main()
{
cin >> n >> m;
for (int i = 1; i <= n; ++i)
{
updata(i, a[i] - a[i - 1]);
}
while (m--){
int ch, x, y, k;
scanf("%d%d", &ch, &x);
if (!ch){
scanf("%d%d", &y, &k);
updata(x, k);
updata(y + 1, -k);
}else{
printf("%d\n", getsum(x));
}
}
return 0;
}