Pagini recente » Monitorul de evaluare | Cod sursa (job #1931141) | Cod sursa (job #1835388) | Cod sursa (job #3153837) | Cod sursa (job #1825013)
#include <iostream>
#include <fstream>
#define lsb(x) (x & (-x))
#define NMAX 15001
#define BUFF_SIZE 100001
using namespace std;
ifstream in("datorii.in");
ofstream out("datorii.out");
int AIB[NMAX], n, m;
int pos = 0;
char buff[BUFF_SIZE];
void Read(int &a)
{
while (!isdigit(buff[pos]))
if (++pos == BUFF_SIZE)
in.read(buff, BUFF_SIZE), pos = 0;
a = 0;
while (isdigit(buff[pos]))
{
a = a * 10 + (buff[pos] - '0');
if (++pos == BUFF_SIZE)
in.read(buff, BUFF_SIZE), pos = 0;
}
}
void Update(int poz, int key)
{
for (int i = poz; i <= n; i += lsb(i))
AIB[i] += key;
}
int Query(int poz)
{
int sum = 0;
for (int i = poz; i >= 1; i -= lsb(i))
sum += AIB[i];
return sum;
}
int main()
{
Read(n), Read(m);
int x, y, z;
for (int i = 1; i <= n; i++)
{
Read(x);
Update(i, x);
}
for (int i = 1; i <= m; i++)
{
Read(x), Read(y), Read(z);
if (x == 0)
Update(y, -z);
else
out << Query(z) - Query(y - 1) << "\n";
}
in.close();
out.close();
return 0;
}