Cod sursa(job #3364242)

Utilizator RegeleOu3433Calin V. Dragos Andrei RegeleOu3433 Data 31 august 2026 17:57:21
Problema Datorii Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.12 kb
#include <bits/stdc++.h>

using namespace std;

const int MAXN = 15e3;
int lsb ( int x ) {
    return x & -x;
}
struct aib {
    int b[MAXN + 1] , sz;
    void update ( int poz , int val ) {
        if ( poz <= sz ) {
            b[poz] += val;
            update ( poz + lsb ( poz ) , val );
        }
    }
    int query1 ( int poz ) {
        if ( poz < 1 )
            return 0;
        return b[poz] + query1 ( poz - lsb ( poz ) );
    }
    int query2 ( int l , int r ) {
        return query1 ( r ) - query1 ( l - 1 );
    }
} aibs;
int main () {
    ifstream fin ( "datorii.in" );
    ofstream fout ( "datorii.out" );
    ios_base :: sync_with_stdio ( false );
    fin.tie ( nullptr );
    fout.tie ( nullptr );
    int n , m , i , cod , t , v , a;

    fin >> n >> m;
    aibs.sz = n;
    for ( i = 1 ; i <= n ; i++ ) {
        fin >> a;
        aibs.update ( i , a );
    }
    for ( i = 1 ; i <= m ; i++ ) {
        fin >> cod >> t >> v;
        if ( cod == 0 )
            aibs.update ( t , -v );
        else
            fout << aibs.query2 ( t , v ) << '\n';
    }
    return 0;
}