Pagini recente » Cod sursa (job #1625435) | Cod sursa (job #3326206) | Cod sursa (job #1315968) | Cod sursa (job #3336565) | Cod sursa (job #3327168)
#include <fstream>
using namespace std;
ifstream cin("datorii.in");
ofstream cout("datorii.out");
#define zeros(x) x&(-x)
const int DIM = 1e5;
class AIB {
public:
int a[DIM];
int n;
AIB() {
for(int i = 0; i < DIM; i ++)
a[i] = 0;
}
void add(int pos, int x) {
for(int i = pos; i <= n; i += zeros(i)) a[i] += x;
}
int compute(int pos) {
int s = 0;
for(int i = pos; i > 0; i -= zeros(i)) s = s + a[i];
return s;
}
};
int n, m;
AIB A = AIB();
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n >> m;
A.n = n;
for(int i = 1; i <= n; i++) {
int x;
cin >> x;
if(x) A.add(i, x);
}
//for(int i = 1; i <= n; i ++) cout<<A.a[i]<<" ";
while(m --) {
int a, b, c;
cin >> a >> b >> c;
if(a == 0) A.add(b, -c);
else cout << A.compute(c) - A.compute(b - 1) << '\n';
}
return 0;
}