Cod sursa(job #2740753)

Utilizator hhhhhhhAndrei Boaca hhhhhhh Data 14 aprilie 2021 10:47:56
Problema Datorii Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.7 kb
#include <bits/stdc++.h>

using namespace std;
ifstream fin("datorii.in");
ofstream fout("datorii.out");
typedef long long ll;
ll arb[300005],n,m;
ll lsb(ll x)
{
    return x&(-x);
}
void update(ll poz, ll val)
{
    for(ll i=poz;i<=n;i+=lsb(i))
        arb[i]+=val;
}
ll suma(ll poz)
{
    ll rez=0;
    for(ll i=poz;i>=1;i-=lsb(i))
        rez+=arb[i];
    return rez;
}
int main()
{
    fin>>n>>m;
    for(int i=1;i<=n;i++)
    {
        ll x;
        fin>>x;
        update(i,x);
    }
    while(m--)
    {
        ll tip,a,b;
        fin>>tip>>a>>b;
        if(tip==0)
            update(a,-b);
        else
            fout<<suma(b)-suma(a-1)<<'\n';
    }
    return 0;
}