Cod sursa(job #1204452)

Utilizator DenisacheDenis Ehorovici Denisache Data 2 iulie 2014 23:08:41
Problema Datorii Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.61 kb
#include <cstdio>
using namespace std;
int N,i,Q,val,AIB[15005];
void Update(int poz,int val)
{
    for (;poz<=N;poz+=poz&-poz) AIB[poz]-=val;
}
int Query(int poz)
{
    int sum=0;
    for (;poz>0;poz-=poz&-poz) sum+=AIB[poz];
    return sum;
}
int main()
{
    freopen("datorii.in","r",stdin);
    freopen("datorii.out","w",stdout);
    scanf("%d %d",&N,&Q);
    for (i=1;i<=N;i++) scanf("%d",&val),Update(i,-val);
    while (Q--)
    {
        int op,x,y;
        scanf("%d %d %d",&op,&x,&y);
        if (op) printf("%d\n",Query(y)-Query(x-1));
        else Update(x,y);
    }
    return 0;
}