Pagini recente » Cod sursa (job #1810114) | Cod sursa (job #180813) | Cod sursa (job #1280861) | Cod sursa (job #1523845) | Cod sursa (job #2182728)
#include<cstdio>
using namespace std;
int aib[100005],sp[100005];
void update(int poz,int val, int n)
{
for ( ;poz<=n;poz+=poz&(-poz))
aib[poz]+=val;
}
int query(int poz)
{
int s=0;
for( ;poz>0;poz-=poz&(-poz))
s+=aib[poz];
return s;
}
int main()
{
freopen("aib.in","r",stdin);
freopen("aib.out","w",stdout);
int x,n,i,j,m,help;
scanf("%d%d",&n,&m);
for(i=1;i<=n;i++)
{
scanf("%d",&x);
sp[i]=sp[i-1]+x;
help=i&(i-1);
if(help==0) help--;
aib[i]=sp[i]-sp[help];
}
int c,x1,x2;
for(i=1;i<=m;i++)
{
scanf("%d%d",&c,&x1);
if(c==0) {scanf("%d",&x2); update(x1,x2,n);}
else if(c==1) { scanf("%d",&x2); printf("%d\n",query(x2)-query(x1-1)); }
else
{
for(j=1;j<=n;j++)
if(query(j)==x1) {printf("%d\n",j); break;}
}
}
return 0;
}