Cod sursa(job #1507820)

Utilizator JustGingaGinga Tudor-Adrian JustGinga Data 21 octombrie 2015 22:27:47
Problema Datorii Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.12 kb
#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;
}