Cod sursa(job #1513273)

Utilizator eu3neuomManghiuc Teodor-Florin eu3neuom Data 29 octombrie 2015 11:24:28
Problema Datorii Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.8 kb
#include <bits/stdc++.h>

using namespace std;

ifstream fin("datorii.in");
ofstream fout("datorii.out");

const int NMax = 15e3 + 5;

int n;
int Aib[NMax];

inline void Update(int pos, const int &sum){
    while(pos <= n){
        Aib[pos] += sum;
        pos += (pos & (-pos));
    }
}

inline int Query(int pos){
    int sum = 0;
    while(pos > 0){
        sum += Aib[pos];
        pos -= (pos & (-pos));
    }
    return sum;
}

int main(){
    int m, type, a, b;
    fin >> n >> m;
    for(int i = 1; i <= n; i++){
        fin >> a;
        Update(i, a);
    }
    for(int i = 1; i <= m; i++){
        fin >> type >> a >> b;
        if(type){
           fout  << Query(b) - Query(a - 1) << "\n";
        } else {
            Update(a, -b);
        }
    }
    return 0;
}