Cod sursa(job #1288641)

Utilizator hasmasandragosHasmasan Dragos hasmasandragos Data 8 decembrie 2014 22:39:37
Problema Datorii Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.26 kb
#include <fstream>
using namespace std;

ifstream f("datorii.in");
ofstream g("datorii.out");

const int nmax=15005;
int arb[44*nmax+69]; // ayy lmao
int be,en,val,poz,suma,n,m,op,i;

void GitGud(int nod , int stanga , int dreapta,int semn)
{
    int mijloc;
    if (stanga==dreapta)
    {
        arb[nod]+=(val*semn);
        return;
    }
    mijloc=(stanga+dreapta)/2;
    if (poz<=mijloc) GitGud(2*nod,stanga,mijloc,semn);
    else GitGud(2*nod+1,mijloc+1,dreapta,semn);
    arb[nod]=arb[2*nod]+arb[2*nod+1];
}

void Dafuq(int nod ,int stanga , int dreapta)
{
    int mijloc;
    if (stanga>=be && dreapta<=en)
    {
        suma+=arb[nod];
        return;
    }
    mijloc=(stanga+dreapta)/2;
    if (be<=mijloc) Dafuq(2*nod,stanga,mijloc);
    if (mijloc<en) Dafuq(2*nod+1,mijloc+1,dreapta);
}

int main()
{
    f>>n>>m;
    for (i=1;i<=n;i++)
    {
        f>>val;
        poz=i;
        GitGud(1,1,n,1);
    }
    while (m--)
    {
        f>>op;
        if (op)
        {
            f>>be>>en;
            suma=0;
            Dafuq(1,1,n);
            g<<suma<<'\n';
        }
        else
        {
            f>>poz>>val;
            GitGud(1,1,n,-1);
        }
    }
    f.close();
    g.close();
    return 0;
}