Cod sursa(job #2784508)
Utilizator | Data | 16 octombrie 2021 16:44:04 | |
---|---|---|---|
Problema | Datorii | Scor | 100 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva de probleme | Marime | 0.54 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;j-=(j&-j))
s+=t[j];
for(j=x-1;j;j-=(j&-j))
s-=t[j];
o<<s<<'\n';
} else
for(j=x;j<=n;j+=(j&-j))
t[j]-=y;
}
return 0;
}