Cod sursa(job #3241155)

Utilizator Tudor.1234Holota Tudor Matei Tudor.1234 Data 27 august 2024 11:43:20
Problema Datorii Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.56 kb
/*
       Implementare cu AIB
*/

#include "bits/stdc++.h"

const int DIM = 15000;
int tree[DIM + 5], n, q;

inline static int lbit(int i){
          return i & (-i);
}

inline static void update(int idx, int val){
            while(idx <= n){
                    tree[idx] = tree[idx] + val;
                    idx  = idx + lbit(idx);
            }
}

inline static long long query(int idx){
           long long sum = 0;
            while(idx > 0){
                  sum += tree[idx];
                  idx = idx - lbit(idx);
            }
            return sum;
}
inline static void Q0(){
          int idx, val;
          std :: cin >> idx >> val;
          update(idx, - val);
}

inline static void Q1(){
           int l, r;
           std :: cin >> l >> r;
           std :: cout << query(r) - query(l - 1) << '\n';
}

inline static void Solve(){
              std :: cin >> n >> q;
               for(int i = 1; i <= n; i++){
                         int x;
                         std :: cin >> x;
                            update(i, x);
               }
               while(q --){
                      int op;
                      std :: cin >> op;
                      if(op == 0){
                            Q0();
                      }
                      if(op == 1){
                            Q1();
                      }
               }
}

signed main(){
     freopen("datorii.in","r",stdin);
     freopen("datorii.out","w",stdout);
     std :: ios_base :: sync_with_stdio(false);
     std :: cin.tie(0);
     std :: cout.tie(0);
     Solve();
        return 0;
}