Pagini recente » Cod sursa (job #1614946) | Cod sursa (job #131568) | Cod sursa (job #1907112) | Cod sursa (job #1798944) | Cod sursa (job #2409068)
/// solutie cu AINT ( arbori de intervale )
#include <bits/stdc++.h>
using namespace std;
ifstream f("datorii.in");
ofstream g("datorii.out");
vector<int> aint;
int n,m,c,st,dr,p,suma(int,int,int);
void upd(int,int);
int main()
{
f>>n>>m;
for(p=1;p<n;p*=2);
aint = vector<int>(2*p,0);
for(int i=p;i<p+n;i++)
f>>aint[i];
for(int i=p-1;i>=1;i--)
aint[i]=aint[2*i]+aint[2*i+1];
for(;m;m--)
{
f>>c>>st>>dr;
if(c==0)
upd(st,-dr);
else
g<<suma(1,1,p)<<'\n';
}
return 0;
}
void upd(int i,int x)
{
i+=p-1;
aint[i]+=x;
for(i/=2;i;i/=2)
aint[i]=aint[2*i]+aint[2*i+1];
}
int suma(int i,int lo,int hi)
{
if(st>hi||lo>dr)return 0;
if(st<=lo&&hi<=dr)return aint[i];
int mi=(lo+hi)/2;
return suma(2*i,lo,mi)+suma(2*i+1,mi+1,hi);
}