Pagini recente » Cod sursa (job #887851) | Cod sursa (job #3140484) | Cod sursa (job #2625170) | Cod sursa (job #2977556) | Cod sursa (job #3134580)
#include <fstream>
using namespace std;
ifstream fin("datorii.in");
ofstream fout("datorii.out");
int n, q, x, tip, a, b, aib[15001];
int lsb(int x) {
return x & -x;
}
int query(int pos) {
int ans = 0;
while(pos) {
ans += aib[pos];
pos -= lsb(pos);
}
return ans;
}
void update(int pos, int val) {
while(pos <= n) {
aib[pos] += val;
pos += lsb(pos);
}
}
int main()
{
fin >> n >> q;
for(int i=1; i<=n; i++) {
fin >> x;
update(i, x);
}
while(q--) {
fin >> tip >> a >> b;
if(tip == 0)
update(a, -b);
else fout << query(b) - query(a-1) << '\n';
}
return 0;
}