Pagini recente » Cod sursa (job #1405498) | Cod sursa (job #2601007) | Cod sursa (job #672102) | Cod sursa (job #2703193) | Cod sursa (job #1507820)
#include <fstream>
using namespace std;
ifstream in ("datorii.in");
ofstream out ("datorii.out");
int n, m, cod, x, y, ind; long long c[15001];
int main()
{
in >> n >> m;
for (int val, i = 1; i <= n; i++)
{
in >> val; ind = i;
for (int poz = 0; ind <= n; poz++)
{
c[ind] = c[ind] + val;
ind = ind + ( (ind ^ (ind - 1)) & ind );
}
}
for (int i = 1; i <= m; i++)
{
in >> cod >> x >> y;
if (cod == 0)
for (int poz = 0; x <= n; poz++)
{
c[x] = c[x] - y;
x = x + ( (x ^ (x - 1)) & x );
}
else
{
long long s1 = 0, s2 = 0;
for (int poz = 0; y; poz++)
{
s1 = s1 + c[y];
y = y - ( (y ^ (y - 1)) & y );
}
x--;
for (int poz = 0; x; poz++)
{
s2 = s2 + c[x];
x = x - ( (x ^ (x - 1)) & x );
}
out << s1 - s2 << '\n';
}
}
out.close(); return 0;
}