Pagini recente » Cod sursa (job #1423848) | Cod sursa (job #2880071) | Cod sursa (job #108037) | Cod sursa (job #1512595) | Cod sursa (job #2843717)
#include <fstream>
#define NMAX 15000
using namespace std;
int aib[NMAX + 1];
int val, n;
inline int lsb (int x){
return x&(-x);
}
void update (int poz, int val){
while (poz <= n){
aib[poz] += val;
poz += lsb(poz);
}
}
int query (int poz){
int sol = 0;
while (poz > 0){
sol += aib[poz];
poz -= lsb(poz);
}
return sol;
}
int main(){
ifstream fin ("datorii.in");
ofstream fout ("datorii.out");
int q;
fin >> n >> q;
for (int i = 1; i <= n; i++){
fin >> val;
update(i, val);
}
int type, a, b;
for (int i = 1; i <= q; i++){
fin >> type >> a >> b;
if (type == 0)
update (a, -b);
else
fout << query (b) - query (a - 1) << "\n";
}
return 0;
}