Pagini recente » Cod sursa (job #1041244) | Cod sursa (job #2372192) | Cod sursa (job #1687560) | Cod sursa (job #17766) | Cod sursa (job #2901098)
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("datorii.in");
ofstream fout("datorii.out");
void update(int *arbIB, int n, int poz, int val){
int ind = poz+1;
while(ind <= n){
arbIB[ind] += val;
ind = ind + (ind&(-ind));
}
}
int query(int *arbIB, int poz){
int s = 0;
int ind = poz;
while(ind > 0){
s += arbIB[ind];
ind = ind - (ind&(-ind));
}
return s;
}
int main()
{
int n, m;
fin >> n >> m;
int arbIB[n+5]={0};
for(int i = 0; i < n; i++){
int x;
fin>>x;
update(arbIB, n, i, x);
}
for(int i = 0; i < m; i++){
int t,x,y;
fin >> t ;
if(t == 1){
fin >> x >> y;
fout << query(arbIB, y) - query(arbIB, x - 1) << '\n';
} else if(t == 0){
fin >> x >> y;
update(arbIB, n, x-1, -y);
}
}
return 0;
}