Pagini recente » Cod sursa (job #3168215) | Cod sursa (job #1327595) | Cod sursa (job #856220) | Cod sursa (job #123223) | Cod sursa (job #1876608)
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("datorii.in");
ofstream fout("datorii.out");
int init[100005],t[400220],a,b,rez;
void construire(int st, int dr, int poz)
{
int x=(st+dr)/2;
if(st==dr){init[st]=poz; return ;}
construire(st, x, 2*poz);
construire(x+1, dr, 2*poz+1);
}
void actualizare(int poz, int val)
{
int x=init[poz];
t[x]=val;
x>>=1;
while(x) t[x]+=val, x>>=1;
}
void actualizare2(int poz, int val)
{
int x=init[poz];
t[x]=t[x]-val;
x>>=1;
while(x) t[x]=t[x]-val, x>>=1;
}
void interogare(int st, int dr, int poz)
{
if(st>b||dr<a) return ;
if(a<=st &&dr <=b) rez=rez+t[poz];
else if(st<dr){
int x=(st+dr)/2;
interogare(st, x, poz*2);
interogare(x+1, dr, poz*2+1);
}
}
int main()
{
int x, n, m;
fin>>n>>m;
construire(1, n, 1);
for(int i=1; i<=n; i++) fin>>x, actualizare(i, x);
for(int i=1; i<=m; i++){
fin>>x>>a>>b;
if(x==1){
rez=0;
interogare(1, n, 1);
fout<<rez<<"\n";
}
else if(x==0) actualizare2(a,b);
}
return 0;
}