Cod sursa(job #2611876)

Utilizator andreic06Andrei Calota andreic06 Data 7 mai 2020 19:18:43
Problema Datorii Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.07 kb
#include <iostream>
#include <cstdio>

using namespace std;
const int N = 15 * 1e3;

int barbati[N+5], f[N+1];
int AIB[N+1];

static inline int baieti ( int x ) {
      return x & ( -x );
}

void update ( int poz, int q, int n ) {
    for ( int i = poz; i <= n; i += baieti( i ) )
       AIB[i] += q;
}

int q ( int poz ) {
   int s = 0;
   for ( int i = poz; i > 0; i -= baieti( i ) )
      s += AIB[i];
   return s;
}

int main()
{
   freopen ( "datorii.in", "r", stdin );
   freopen ( "datorii.out", "w", stdout );
   ios::sync_with_stdio (false);
   cin.tie (), cout.tie ();

   int n, t, CASE;

   cin >> n >> t;
   for ( int i = 1; i <= n; i ++ )
       cin >> barbati[i], f[i] = f[i-1] + barbati[i];

   for ( int i = 1; i <= n; i ++ )
      AIB[i] = f[i] - f[i-baieti(i)];

   for ( int i = 1; i <= t; i ++ ) {
      cin >> CASE;

      if ( CASE == 0 ) {
        int x, poz;
        cin >> poz >> x;
        update ( poz, -x, n );
      }
      else {
        int st, dr;
        cin >> st >> dr;
        cout << q ( dr ) - q ( st - 1 ) << '\n';
      }
   }
    return 0;
}