Cod sursa(job #1448573)

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