Cod sursa(job #3328775)
| Utilizator | Data | 10 decembrie 2025 12:22:51 | |
|---|---|---|---|
| Problema | Datorii | Scor | 100 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva de probleme | Marime | 0.9 kb |
#include <fstream>
#include <math.h>
using namespace std;
ifstream cin("datorii.in");
ofstream cout("datorii.out");
int v[15001],btg[124];
int main()
{
int n,m,q,n3,y,x,tip,s;
cin>>n>>m;
q=sqrt(n);
for(int n2=0;n2<n;n2++) {
cin>>v[n2];
btg[n2/q]+=v[n2];
}
for(int n2=1;n2<=m;n2++) {
cin>>tip>>y>>x;
y--;
if(tip==0) {
btg[y/q]-=x;
v[y]-=x;
}
if(tip==1) {
s=0;
x--;
while(y%q!=0 && y<=x)
{
s+=v[y];
y++;
}
while(y+q<x)
{
s+=btg[y/q];
y+=q;
}
while(y<=x)
{
s+=v[y];
y++;
}
cout<<s<<'\n';
}
}
return 0;
}
