Pagini recente » Cod sursa (job #1871055) | Cod sursa (job #1015458) | Cod sursa (job #1163059) | Cod sursa (job #2660382) | Cod sursa (job #2937923)
#include <fstream>
using namespace std;
ifstream cin("datorii.in");
ofstream cout("datorii.out");
int n, m;
int aib[15001];
int lsb(int n)
{
return n & (-n);
}
void Build(int x, int value)
{
for(int i = x; i <= n; i += lsb(i))
aib[i] += value;
}
void Update(int x, int value)
{
for(int i = x; i <= n; i += lsb(i))
aib[i] = max(0, aib[i] - value);
}
int Query(int x)
{
int sum = 0;
for(int i = x; i > 0; i -= lsb(i))
sum += aib[i];
return sum;
}
int main()
{
cin >> n >> m;
for(int i = 1; i <= n; i++)
{
int x;
cin >> x;
Build(i, x);
}
for(int i = 1; i <= m; i++)
{
int tip, x, y;
cin >> tip >> x >> y;
if(tip == 0)
Update(x, y);
else
cout << Query(y) - Query(x - 1) << '\n';
}
return 0;
}