Pagini recente » Cod sursa (job #3338512) | Cod sursa (job #2094957) | Cod sursa (job #123342) | Cod sursa (job #2105236) | Cod sursa (job #3312794)
#include <fstream>
using namespace std;
ifstream cin("datorii.in");
ofstream cout("datorii.out");
int v[15001];
int aib[15001];
int n,m;
int lsb (int x) {
return x & (-x);
}
int query (int pos) {
int sum=0;
while (pos>0) {
sum+=aib[pos];
pos-=lsb(pos);
}
return sum;
}
void update (int pos, int increment) {
while (pos<=n) {
aib[pos]+=increment;
pos+=lsb(pos);
}
}
void scadere (int pos, int increment) {
while (pos<=n) {
aib[pos]-=increment;
pos+=lsb(pos);
}
}
int main() {
cin>>n>>m;
for (int i=1; i<=n; ++i) {
cin>>v[i];
update(i,v[i]);
}
int tip,a,b;
for (int i=1; i<=m; ++i) {
cin>>tip>>a>>b;
if (!tip) scadere(a,b);
else cout<<query(b)-query(a-1)<<'\n';
}
}