Pagini recente » Cod sursa (job #1915298) | Cod sursa (job #2125296) | Cod sursa (job #1436022) | Cod sursa (job #2497719)
#include <iostream>
#include <fstream>
using namespace std;
ifstream f("datorii.in");
ofstream g("datorii.out");
int aib[16000], n, m;
int k2(int x){
return ((x ^ (x - 1)) & x);
}
int updoot(int x){
return x + k2(x);
}
int downdoot(int x){
return x - k2(x);
}
void removal(int i, int x){
for(; i <= n; i = updoot(i)){
aib[i] -= x;
}
}
int f1tx(int i){
int sum = 0;
for(; i > 0; i = downdoot(i)){
sum += aib[i];
}
return sum;
}
int blyat(int x, int y){
if(x < y)
swap(x, y);
return f1tx(x) - f1tx(y - 1);
}
int main() {
f>>n>>m;
for (int i = 1; i <= n; ++i) {
int x;
f>>x;
removal(i, -x);
}
for (int j = 0, x, y; j < m; ++j) {
int cod;
f>>cod>>x>>y;
if(cod == 0){
removal(x, y);
}else{
g<<blyat(x, y)<<'\n';
}
}
return 0;
}