Pagini recente » Cod sursa (job #1249392) | Cod sursa (job #301663) | Cod sursa (job #1009380) | Cod sursa (job #68073) | Cod sursa (job #2570032)
#include <iostream>
#include <fstream>
#define NMAX 15000
using namespace std;
ifstream f("datorii.in");
ofstream g("datorii.out");
int n, q, aib[NMAX+10];
void update(int poz, int val)
{ while(poz <= n)
{ aib[poz] += val;
int lsb = poz & (-poz);
poz += lsb;
}
}
int query(int poz)
{ int ans = 0;
while(poz)
{ ans += aib[poz];
int lsb = poz & (-poz);
poz -= lsb;
}
return ans;
}
int main()
{
f >> n >> q;
for(int i=1; i<=n; i++)
{ int x;
f >> x;
update(i, x);
}
while(q--)
{ int type, a, b;
f >> type >> a >> b;
if(!type) update(a, -b);
else g << query(b) - query(a-1) << '\n';
}
return 0;
}