Cod sursa(job #3291359)

Utilizator David_Popa123Popa David Matei David_Popa123 Data 4 aprilie 2025 13:44:58
Problema Datorii Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.72 kb
#include <bits/stdc++.h>

using namespace std;

#define MAXN 15000

int aib[MAXN + 1];

ifstream fin( "datorii.in" );
ofstream fout( "datorii.out" );

int n;

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

void update( int p, int x ) {
    for( ; p <= n; p += ( p & -p ) )
        aib[p] += x;
}

int main() {
    int q, x, a, b, i;

    fin >> n >> q;
    for( i = 1; i <= n; i++ ) {
        fin >> x;
        update( i, x );
    }

    while( q-- ) {
        fin >> x >> a >> b;
        if( x > 0 )
            fout << query( b ) - query( a - 1 ) << '\n';
        else
            update( a, -b );
    }

    return 0;
}