Cod sursa(job #2916631)

Utilizator AlexandruBenescuAlexandru Benescu AlexandruBenescu Data 30 iulie 2022 22:57:00
Problema Datorii Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.72 kb
#include <bits/stdc++.h>
#define L 15005
#define lsb(x) (x & (-x))
using namespace std;
ifstream fin("datorii.in");
ofstream fout("datorii.out");
int v[L], aib[L], n;

inline void update(int pos, int val){
  for (; pos <= n; pos += lsb(pos))
    aib[pos] += val;
}

inline int query(int pos){
  int ret = 0;
  for (; pos; pos -= lsb(pos))
    ret += aib[pos];
  return ret;
}

int main(){
  int m, i, t, x, y;
  fin >> n >> m;
  for (i = 1; i <= n; i++){
    fin >> v[i];
    update(i, v[i]);
  }
  for (i = 1; i <= m; i++){
    fin >> t >> x;
    if (t == 0){
      fin >> y;
      update(x, -y);
    }
    else{
      fin >> y;
      fout << query(y) - query(x - 1) << "\n";
    }
  }
  return 0;
}