Pagini recente » Cod sursa (job #1544276) | Cod sursa (job #2461869) | Cod sursa (job #145513) | Cod sursa (job #2130800) | Cod sursa (job #556485)
Cod sursa(job #556485)
#include <fstream>
using namespace std;
#define FIN "aib.in"
#define FOUT "aib.out"
#define dim 100001
int a[dim];
long n;
long search(long x)
{
long mij;
for(long st=1, dr=n; st<=dr;)
{
mij = (st+dr)/2;
if(a[mij] == x)
return mij;
else if(a[mij] < x)
st = mij+1;
else
dr = mij-1;
}
return -1;
}
long sum(long poz)
{
long c, s; c=s=0;
while(poz > 0)
{
s += a[poz];
while( !(poz & (1<<c)) )
c++;
poz -= (1<<c);
}
return s;
}
void update(long poz, int val)
{
int c=0;
while(poz <= n)
{
a[poz] += val;
while( !(poz & (1<<c)) )
c++;
poz += (1<<c);
}
}
void citire()
{
long x, y; long m;
freopen(FIN,"r",stdin); scanf("%ld %ld", &n, &m);
for(long i=1; i<=n; i++)
{
scanf("%ld", &x);
update(i, x);
}
int k;
for(long i=1; i<=m; i++)
{
scanf("%d", &k);
if(k < 2)
{
scanf("%ld %ld", &x, &y);
if(!k)
update(x, y);
else
printf("%ld\n", sum(y)-sum(x-1));
}
else
{
scanf("%ld", &x);
printf("%ld\n", search(x));
}
}
}
int main()
{
freopen(FOUT,"w",stdout);
citire();
return 0;
}