全用int才对,树状数组。
#include <iostream>
#include <cstdio>
#include <cstring>
const int MAX = 1e5 + 5;
int arr[MAX];
int n, q;
inline int lowbit(int x)
{
return x & (-x);
}
int update(int k, int num)
{
while (k <= n)
{
arr[k] += num;
k += lowbit(k);
}
return 0;
}
int sum(int k)
{
int res = 0;
while (k)
{
res += arr[k];
k -= lowbit(k);
}
return res;
}
int main()
{
int t, cas = 0;
scanf("%d",&t);
while (t--)
{
memset(arr, 0, sizeof(arr));
int tmp;
scanf("%d%d",&n, &q);
for (int i = 1; i != n + 1; ++i)
{
scanf("%d", &tmp);
update(i, tmp);
}
int type, st, ed, pos, val;
printf("Case %d:\n", ++cas);
for (int i = 0; i != q; ++i)
{
scanf("%d", &type);
if (type == 1)
{
scanf("%d", &pos);
printf("%d\n", sum(pos + 1) - sum(pos));
update(pos + 1, sum(pos) - sum(pos + 1));
}
else if (type == 2)
{
scanf("%d%d", &pos, &val);
update(pos + 1, val);
}
else if (type == 3)
{
scanf("%d%d", &st, &ed);
printf("%d\n", sum(ed + 1) - sum(st));
}
}
}
return 0;
}