Cod sursa(job #3359554)

Utilizator RuxandraPro12_Metehau Ruxandra Maria RuxandraPro12_ Data 30 iunie 2026 11:20:04
Problema Datorii Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.83 kb
#include <iostream>
#include <fstream>
#include <algorithm>

using namespace std;

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

const int N = 15e3;

int n, m, arbore[N + 5];

void update (int poz, int val) {
    while (poz <= n) {
        arbore[poz] += val;
        poz += poz & -poz;
    }
}

int query (int poz) {
    int s = 0;
    while (poz > 0) {
        s += arbore[poz];
        poz -= poz & -poz;
    }
    return s;
}

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