Pagini recente » Cod sursa (job #967511) | Cod sursa (job #1857488)
#include <iostream>
#include <fstream>
#define MAX 15005
using namespace std;
ifstream fin ("datorii.in");
ofstream fout ("datorii.out");
int n, m, aib[MAX];
void update(int poz, int val){
for(; poz <= n; poz += (poz & (-poz)))
aib[poz]+=val;
}
int query(int poz){
int rez= 0;
for(; poz > 0; poz -= poz & (-poz))
rez += aib[poz];
return rez;
}
int main()
{
fin>>n>>m;
for(int i = 1; i <= n; ++i){
int x;
fin >> x;
update(i, x);
}
for(int i = 1; i<=m; ++i){
int x, y, z;
fin >> x >> y >> z;
if( x == 1 ){
if( y == 1 )
cout << query(z) << ' ';
else
cout << query(z) - query(y-1) << ' ';
}
else{
if(aib[y] >= z)
update(y, -z);
else
update(y, -aib[y]);
}
}
return 0;
}