Cod sursa(job #1216315)

Utilizator azkabancont-vechi azkaban Data 4 august 2014 09:27:48
Problema Datorii Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.71 kb
#include <iostream>
using namespace std;
void openIOFiles()
{
 freopen("datorii.in","r",stdin);
 freopen("datorii.out","w",stdout);
}
int i,n,k,op,T,V,aux;
int A[16013];

int fnsb(int x)
{
 return x&(-x);
}

void update(int nod, int val)
{
 for (int i=nod;i<=n;i+=fnsb(i)) A[i]+=val;
}

int query(int poz)
{
 int i,s(0);
 for (i=poz;i>0;i-=fnsb(i)) s+=A[i];
 return s;
}

int main()
{
 openIOFiles();
 cin>>n>>k;
 for (i=1;i<=n;++i){
                    cin>>aux;
                    update(i,aux);
                    }
 while(k--){
            cin>>op>>T>>V;
            if (op==0) update(T,-V);
            if (op==1) cout<<query(V)-query(T-1)<<"\n";
            }
return 0;
}