Cod sursa(job #2784510)

Utilizator BlaugranasEnal Gemaledin Blaugranas Data 16 octombrie 2021 16:46:29
Problema Datorii Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.49 kb
#include<fstream>
using namespace std;
int n,m,x,y,j,s,t[15001];
bool c;
ifstream f("datorii.in");
ofstream o("datorii.out");
int main()
{
    for(f>>n>>m,y=1;y<=n;++y)
        for(f>>x,j=y;j<=n;j+=(j&-j))
            t[j]+=x;
    while(m--) {
        f>>c>>x>>y;
        if(c) {
            for(s=0,j=y;j;s+=t[j],j-=(j&-j));
            for(j=x-1;j;s-=t[j],j-=(j&-j));
            o<<s<<'\n';
        } else
            for(j=x;j<=n;t[j]-=y,j+=(j&-j));
    }
    return 0;
}