Cod sursa(job #3338869)

Utilizator ChircaTChirca Teodor ChircaT Data 5 februarie 2026 12:39:02
Problema Datorii Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.04 kb
#include <fstream>
using namespace std;


//datorii///////////////////////////////////////////

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

int N, M;
long long BIT[15001];

int main() {
    fin >> N >> M;

    for (int i = 1; i <= N; i++) {
        long long x;
        fin >> x;
        int j = i;
        while (j <= N) {
            BIT[j] += x;
            j += j & (-j);
        }
    }

    for (int i = 1; i <= M; i++) {
        int tip, a, b;
        fin >> tip >> a >> b;

        if (tip == 0) {
            int j = a;
            while (j <= N) {
                BIT[j] -= b;
                j += j & (-j);
            }
        } else {
            long long s = 0;
            int x = b;
            while (x > 0) {
                s += BIT[x];
                x -= x & (-x);
            }

            x = a - 1;
            while (x > 0) {
                s -= BIT[x];
                x -= x & (-x);
            }

            fout << s << "\n";
        }
    }

    return 0;
}