Cod sursa(job #2965738)

Utilizator gabriel10tm@gmail.comGabriel Marian [email protected] Data 15 ianuarie 2023 23:27:07
Problema Datorii Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.71 kb
#include <bits/stdc++.h>
using namespace std;
const int nmx = 15e3+1;
#define ll long long
ll a[nmx];
int n,m;
#if 1
ifstream fin("datorii.in");
ofstream fout("datorii.out");
#define cin fin
#define cout fout
#endif // 0
ll q(int i){
    ll res = 0;
    for(;i>0;i-=i&-i)
        res += a[i];
    return res;
}

void u(int i,int add){
    for(;i<=n;i+=i&(-i))
        a[i] += add;
}

int main(){
    cin >> n >> m;
    for(int i=1;i<=n;i++){
        int x;
        cin >> x;
        u(i,x);
    }
    while(m--){
        int op,a,b;
        cin >> op >> a >> b;
        if(op == 0){
            u(a,-b);
        }
        else{
            cout << q(b) - q(a-1) << "\n";
        }
    }
}