Pagini recente » Cod sursa (job #666350) | Cod sursa (job #2284925) | Cod sursa (job #2730630) | Cod sursa (job #287320) | Cod sursa (job #1619260)
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
ifstream fin ("datorii.in");
ofstream fout ("datorii.out");
vector <int> AIB;
int N, M;
void Form (int pos, int value)
{
while (pos <= N)
{
AIB[pos] += value;
pos += (pos&(-pos));
}
}
void Update (int pos, int value)
{
while (pos <= N)
{
AIB[pos] -= value;
pos += (pos&(-pos));
}
}
int Query (int pos)
{
int s = 0;
while (pos > 0)
{
s += AIB[pos];
pos -= (pos&(-pos));
}
return s;
}
int main()
{
fin >>N >>M;
AIB.resize(N+1);
for (int i = 1; i <= N; ++i)
{
int x;
fin >>x;
Form(i,x);
}
for (int i = 1; i <= M; ++i)
{
int type, x, y;
fin >>type >>x >>y;
if (type == 0)
Update(x,y);
else
fout <<Query(y) - Query(x-1) <<'\n';
}
return 0;
}