Pagini recente » Cod sursa (job #3338870) | Cod sursa (job #2440952) | Cod sursa (job #2193553) | Cod sursa (job #2179896) | Cod sursa (job #3338857)
#include <fstream>
using namespace std;
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;
}