Pagini recente » Cod sursa (job #92754) | Cod sursa (job #589100) | Cod sursa (job #1621638) | Cod sursa (job #1252715) | Cod sursa (job #1251816)
/// Craciun Catalin
/// Datorii
#include <iostream>
#include <fstream>
#include <cmath>
const int NMax = 20000;
using namespace std;
ifstream f("datorii.in");
ofstream g("datorii.out");
int n, m;
int A[NMax];
void insertInBinaryTree(int position, int value) {
while (position <= n) {
A[position] += value;
int zeros = 0; while (!(position & (1<<zeros))) zeros++;
position += 1<<zeros;
}
}
int queryBinaryTree(int right) {
int sum = 0;
while (right > 0) {
sum += A[right];
int zeros = 0; while (!(right & (1<<zeros))) zeros++;
right -= 1<<zeros;
}
return sum;
}
int main() {
f>>n>>m;
for (int i=1;i<=n;i++) {
int x; f>>x;
insertInBinaryTree(i, x);
}
for (int i=1;i<=m;i++) {
int type;
f>>type;
if (type == 0) {
int t,v;
f>>t>>v;
insertInBinaryTree(t,-v);
} else if (type == 1) {
int left, right;
f>>left>>right;
g<<queryBinaryTree(right) - queryBinaryTree(left-1)<<'\n';
}
}
f.close(); g.close();
return 0;
}