Cod sursa(job #3253984)

Utilizator Luca_georgescuLucageorgescu Luca_georgescu Data 5 noiembrie 2024 17:38:12
Problema Datorii Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.71 kb
#include <bits/stdc++.h>

using namespace std;

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

bool q;
int n,m,a[15005],aib[15005],x,y;

int query(int i)
{
    int sum=0;
    while ( i>0 )
    {
        sum+=aib[i];
        i-=(i&-i);
    }
    return sum;
}

void update(int i, int val)
{
    while ( i<=n )
    {
        aib[i]+=val;
        i+=(i&-i);
    }
}

int main()
{
    f >> n >> m;
    for (int i=1; i<=n; i++ )
    {
        f >> x;
        update(i,x);
    }
    for (int i=1; i<=m; i++ )
    {
        f >> q >> x >> y;
        if ( q==0 )
            update(x,-y);
        else if ( q==1 )
            g << query(y)-query(x-1) << '\n';
    }
    return 0;
}