Cod sursa(job #1448538)

Utilizator enedumitruene dumitru enedumitru Data 7 iunie 2015 14:02:30
Problema Datorii Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.55 kb
#include<fstream>
using namespace std;
ifstream f("datorii.in"); ofstream g("datorii.out");
int AIB[15010],m,n;
inline int zero(int x) {return (-x)&x;}
void update(int poz, int val)
{   while(poz <= n) {AIB[poz]+=val; poz+=zero(poz);}}
int calc(int poz)
{   int s=0;
    while(poz) {s+=AIB[poz]; poz-=zero(poz);}
    return s;
}
int main()
{   int i,tip,x,y;
    f>>n>>m;
    for(i=1;i<=n;++i) {f>>x; update(i,x);}
    while(m--)
    {   f>>tip>>x>>y;
        if(tip) g<<calc(y)-calc(x-1)<<"\n"; else update(x,-y);
    }
    return 0;
}