Cod sursa(job #1603405)

Utilizator AlexandraaaaMereu Alexandra Alexandraaaa Data 17 februarie 2016 15:01:20
Problema Datorii Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.69 kb
#include <iostream>
#include <vector>
#include <fstream>
#define maxN 15000 + 5

using namespace std;

int bit[maxN], n;

void update (int x, int i){
  for(int j = i; j <= n; j += j & (-j))
    bit[j] += x;
}

long long sum(int r){
  long long sum = 0;

  for(int i = r; i > 0; i -= i & (-i))
    sum += bit[i];

  return sum;
}

int main()
{
  ifstream f("datorii.in");
  ofstream g("datorii.out");

  int m;
  f >> n >> m;

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

  for (int i = 0; i < m; ++i){
    int x, y, z;
    f >> x >> y >> z;

    if(x == 0)
      update(-z, y);
    else
      g << sum(z) - sum(y-1) << '\n';
  }

  f.close();
  g.close();

  return 0;
}