Pagini recente » Cod sursa (job #1854467) | Cod sursa (job #3345861) | Cod sursa (job #3326433) | Cod sursa (job #935870) | Cod sursa (job #3329053)
#include <bits/stdc++.h>
#define ll long long
#define F first
#define S second
using namespace std;
const ll MOD=1e9+7;
const string filename="datorii";
ifstream fin(filename+".in");
ofstream fout(filename+".out");
int main()
{
ios_base::sync_with_stdio(false);
fin.tie(nullptr);
ll n,og,q;
fin>>og>>q;
n=og;
while(n!=(n&(-n)))n+=n&(-n);
vector<ll> v(n*2,0);
for(ll i=0;i<og;i++){
ll x=n+i;
fin>>v[x];
x/=2;
while(x>0){
v[x]=v[x*2]+v[x*2+1];
x/=2;
}
}
for(ll i=0;i<q;i++){
ll a,b,c;
fin>>c>>a>>b;
if(c==0){
ll x=a+n-1;
v[x]-=b;
x/=2;
while(x>0){
v[x]=v[x*2]+v[x*2+1];
x/=2;
}
}
else{
ll pos=a,ans=0,x,ch,l=0,lc;
while(pos<=b){
ch=1;
x=pos+n-1;
l=pos+n-1;
lc=1;
while(x%2==0 && pos+ch-1<=b){
l=x;
lc=ch;
x/=2;
ch*=2;
}
ans+=v[l];
pos=pos+lc;
}
fout<<ans<<'\n';
}
}
return 0;
}