Pagini recente » Cod sursa (job #217382) | Cod sursa (job #1226542) | Cod sursa (job #3142492) | Cod sursa (job #523804) | Cod sursa (job #1319600)
#include <cstdio>
#define nmax 15015
#define lb(x) (x&(-x))
using namespace std;
int aib[nmax];
int x, y, i, n, m, type;
int tree_query(int position)
{
int s=0;
for(int i=position; i>0; i-=lb(i)) s+=aib[i];
return s;
}
int tree_add(int value, int position)
{
for(int i=position; i<=n; i+=lb(i)) aib[i]+=value;
}
int main()
{
freopen("datorii.in", "rt", stdin);
freopen("datorii.out", "wt", stdout);
scanf("%d%d", &n, &m);
for(i=1; i<=n; ++i)
{
scanf("%d", &x);
tree_add(x, i);
}
for(i=1; i<=m; ++i)
{
scanf("%d", &type);
if(type)
{
scanf("%d%d", &x, &y);
printf("%d\n", tree_query(y)-tree_query(x-1));
}
else
{
scanf("%d%d", &x, &y);
tree_add(-y, x);
}
}
return 0;
}