Cod sursa(job #2637358)

Utilizator Iustin01Isciuc Iustin - Constantin Iustin01 Data 22 iulie 2020 17:04:39
Problema Datorii Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.81 kb
#include <bits/stdc++.h>
#define MAX 20005
#define lsb(x) (x & (-x))
using namespace std;

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


int AIB[MAX];
int n, m, val, poz, caz;

void update(){
    for(int i = poz; i <= n; i += lsb(i))
        AIB[i] += val;
}

void update1(){
    for(int i = poz; i <= n; i += lsb(i))
        AIB[i] -= val;
}


int query(int y){
    unsigned long long int sum = 0;
    for(int i = y; i > 0; i -= lsb(i))
        sum += AIB[i];
    return sum;
}

int main(){
    in>>n>>m;
    for(int i = 1; i <= n; i++){
        in>>val;
        poz = i;
        update();
    }
    for(int i = 1; i <= m; i++){
        in>>caz>>poz>>val;
        if(!caz)
            update1();
        else
            out<<(query(val) - query(poz - 1))<<"\n";
    }
}