Cod sursa(job #1867070)

Utilizator radu.leonardoThe Doctor radu.leonardo Data 3 februarie 2017 18:29:10
Problema Datorii Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.79 kb
#include <cstdio>
#define NMAX 15001
using namespace std;

FILE*f=freopen("datorii.in","r",stdin);
FILE*g=freopen("datorii.out","w",stdout);
int n,m,t[2 * NMAX],q,a,b,sum;



int main()
{
    scanf("%d %d", &n,&m);
    for (int i = 0; i < n; ++i) scanf("%d", t + n + i);
    for (int i = n - 1; i > 0; --i) t[i] = t[i<<1] + t[i<<1|1];

    while(m--)
    {
        scanf("%d %d %d", &q,&a,&b);

        if(q==1)
        {sum=0;a--;
                         for (a+= n, b += n; a < b; a >>= 1, b >>= 1)
                {   if (a&1) sum += t[a++];
                    if (b&1) sum += t[--b];
                }

    printf("%d\n",sum);

        }

        else
        {
            a--;
            for (t[a += n] -= b; a> 1; a >>= 1) t[a>>1] -= b;
        }
    }


}