Pagini recente » Cod sursa (job #2139157) | Cod sursa (job #2379159) | Cod sursa (job #2754242) | Cod sursa (job #3135531) | Cod sursa (job #3252339)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("datorii.in");
ofstream fout("datorii.out");
int n, m, i, k, s[125], a[15005], j, x, y, c, stk, stp, drk, drp, ans, lg;
void suma(int x, int y) {
stk=(x+k-1)/k;
if (x%k==0) stk++;
drk=(y+k-1)/k;
if (y%k==1) drk--;
ans=0;
while (x%k!=1) {
ans+=a[x];
x++;
}
while (y%k!=0) {
ans+=a[y];
y--;
}
for (j=stk; j<=drk; j++) ans+=s[j];
fout<<ans<<'\n';
}
void update(int x, int y) {
if (x%k==0) s[x/k]-=y;
else s[x/k+1]-=y;
a[x]-=y;
}
int main()
{
fin>>n>>m;
k=int(sqrt(n))+1;
for (i=1; i<=n; i++) {fin>>x; update(i, -x);}
for (i=1; i<=m; i++) {
fin>>c>>x>>y;
if (c==0) update(x, y);
else suma(x, y);
}
return 0;
}