Pagini recente » Cod sursa (job #1122420) | Cod sursa (job #3172413) | Cod sursa (job #2447386) | Cod sursa (job #1080122) | Cod sursa (job #2426351)
#include <fstream>
using namespace std;
ifstream f("datorii.in");
ofstream g("datorii.out");
int i, aib[15001], n, m, op, number, a, b;
void update(int x, int value){
while(x <= n){
aib[x] = aib[x] + value;
x = x + (x & (- x));
}
}
int quary(int x){
int s = 0;
while(x >= 1){
s = aib[x] + s;
x = x - (x & (- x));
}
return s;
}
int main()
{ f >> n >> m;
for(i = 1; i <= n; i++){
f >> number;
update(i, number);
}
for(i = 1; i <= m; i++){
f >> op >> a >> b;
if(op == 0)
update(a, - b);
else
g << quary(b) - quary(a - 1) << '\n';
}
return 0;
}