Pagini recente » Cod sursa (job #216927) | Cod sursa (job #918852) | Cod sursa (job #2948175) | Cod sursa (job #1409113) | Cod sursa (job #1202974)
#include <cstdio>
using namespace std;
int n, m;
int a[15005], aib[15005];
void build_tree(int poz, int val)
{
for(;poz<=n;poz+=(poz&(-poz)))
aib[poz]+=val;
}
void upgrade(int poz, int val)
{
for(;poz<=n;poz+=(poz&(-poz)))
aib[poz]-=val;
}
int query(int poz)
{
int s=0;
for(;poz>=1;poz-=(poz&(-poz)))
s+=aib[poz];
return s;
}
int main()
{
freopen("datorii.in", "r", stdin);
freopen("datorii.out", "w", stdout);
scanf("%d%d", &n, &m);
for(int i=1;i<=n;i++)
{
int x;
scanf("%d", &x);
build_tree(i, x);
}
for(int i=0;i<m;i++)
{
bool type;
int x, y;
scanf("%d%d%d", &type, &x, &y);
if(type==0)
{
upgrade(x, y);
}
else
{
printf("%d\n", query(y)-query(x-1));
}
}
return 0;
}