Pagini recente » Cod sursa (job #3319008) | Cod sursa (job #3320650) | Cod sursa (job #3334506) | Cod sursa (job #3306679) | Cod sursa (job #3309575)
#include <fstream>
using namespace std;
ifstream fin("datorii.in");
ofstream fout("datorii.out");
int n, m;
int x, y;
int tip;
int aib[100005];
void adaugare(int poz, int val) {
while(poz <= n){
aib[poz] += val;
poz += poz & (-poz);
}
}
void scadere(int poz, int val) {
while(poz <= n){
aib[poz] -= val;
poz += poz & (-poz);
}
}
int suma(int x, int y) {
if(x != 1){
return suma(1, y) - suma(1, x-1);
}
int suma_tot = 0;
while(y > 0) {
suma_tot += aib[y];
y -= (y & (-y));
}
return suma_tot;
}
int main(){
fin >> n >> m;
for(int i = 1; i <= n; i++) {
fin >> x;
adaugare(i, x);
}
for(int i = 1; i <= m; i++) {
fin >> tip;
if(tip == 0) {
fin >> x >> y;
scadere(x, y);
}
else if(tip == 1) {
fin >> x >> y;
fout << suma(x, y) << '\n';
}
}
return 0;
}