Cod sursa(job #1730528)

Utilizator MihalachiRazvanMihalachi Razvan MihalachiRazvan Data 17 iulie 2016 00:47:58
Problema Datorii Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.19 kb
#include <fstream>
using namespace std;
ifstream fin("datorii.in");
ofstream fout("datorii.out");
#define MAX 100001
#define dim 100001
long long i,n,m,j,t,q,p,v,s,k,binar,a,ki,bi[dim];
int getparent(int x)
{
    return x-( (x ^ (x - 1)) & x );
}
int getnext(int x)
{
    return x+( (x ^ (x - 1)) & x );
}
int suma(int x)
{
    if(x==0)
        return 0;
    else
        return bi[x]+bi[getparent(x)];
}
int main()
{
    fin>>n>>m;
       for(i=1;i<=n;i++)
        {fin>>a;
         j=i;
         while(j<=n)
         {
           bi[j]=bi[j]+a;
           j=getnext(j);
         }
          }
          for(j=1;j<=m;j++)
          {
              fin>>binar>>p>>q;
              if(binar==1)
              {
                  if(p==1)
                    fout<<suma(q);
                  else
                    fout<<suma(q)-suma(p-1);
                    fout<<"\n";
              }
              if(binar==0)
              {
                  while(p<=n)
                  {
                      bi[p]=bi[p]-q;
                      p=getnext(p);
                  }
                 }
          }

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