Pagini recente » Cod sursa (job #705387) | Cod sursa (job #568924) | Cod sursa (job #2220088) | Cod sursa (job #2139800) | Cod sursa (job #2193215)
#include <fstream>
using namespace std;
ifstream in("datorii.in");
ofstream out("datorii.out");
int n, m, AIB[15001];
void Add(int poz, int quantity)
{
for(; poz<=n; poz+=poz&-poz)
AIB[poz] += quantity;
}
int Compute(int poz)
{
int sum = 0;
for(; poz>0; poz-=poz&-poz)
sum += AIB[poz];
return sum;
}
int main()
{
in >>n >>m;
for( int i = 1; i <= n; i++)
{
int x;
in >>x;
Add(i,x);
}
while( m-- )
{
int q, x, y;
in >>q >>x >>y;
if(q)
out<<Compute(y) - Compute(x-1)<<endl;
else
Add(x, -y);
}
return 0;
}