Cod sursa(job #1730542)

Utilizator MihalachiRazvanMihalachi Razvan MihalachiRazvan Data 17 iulie 2016 02:07:39
Problema Datorii Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.8 kb
#include <fstream>
#include <iostream>
#define dim 100001
#define zeros(x) ( (x ^ (x - 1)) & x )
using namespace std;
ifstream fin("datorii.in");
ofstream fout("datorii.out");
int AIB[dim],a,x,y,b,i,n,m;
void ADD(int x,int y)
{
    for(int j=x;j<=n;j=j+zeros(j))
        AIB[j]=AIB[j]+y;
}
int compute(int x)
{
    int sum=0;
    for(int j=x;j>0;j=j-zeros(j))
        sum=sum+AIB[j];
    return sum;
}
int main()
{
    fin>>n>>m;
         for(i=1;i<=n;i++)
         {
             fin>>a;
             ADD(i,a);
         }
         for(i=1;i<=m;i++)
         {
             fin>>b>>x>>y;
             if(b==0)
                 ADD(x,-y);
                 else
            fout<<compute(y)-compute(x-1)<<"\n";
         }

     fin.close();
     fout.close();
    return 0;
}