Pagini recente » Cod sursa (job #1282344) | Cod sursa (job #76937) | Cod sursa (job #1723772) | Cod sursa (job #73418) | Cod sursa (job #1206544)
#include <cstdio>
using namespace std;
const int DIM = 1000000;
int AIB[DIM+5], N, M;
void Upgrade(int i, int Val)
{
for(; i <= N; i+=i&-i)
AIB[i] -= Val;
}
void AddElement(int i, int Val)
{
for(; i<= N; i+=i&-i)
AIB[i] += Val;
}
int Query(int i)
{
int S=0;
for(; i; i-=i&-i) S+=AIB[i];
return S;
}
int QueryAB(int Begin, int End)
{
return Query(End) - Query(Begin-1);
}
int main()
{
freopen("datorii.in", "r", stdin);
freopen("datorii.out", "w", stdout);
int i, Aux, Type, A1, A2;
scanf("%d %d", &N, &M);
for(i=1; i<=N; i++)
{
scanf("%d", &Aux);
AddElement(i,Aux);
}
for(i=1; i<=M; i++)
{
scanf("%d %d %d", &Type, &A1, &A2);
if(!Type) Upgrade(A1,A2);
else printf("%d\n", QueryAB(A1,A2));
}
return 0;
}