Pagini recente » Cod sursa (job #1832283) | Cod sursa (job #976541) | Cod sursa (job #569088) | Cod sursa (job #844619) | Cod sursa (job #2564744)
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
ifstream fin("aib.in");
ofstream fout("aib.out");
const int NMAX = 100009;
int AIB[NMAX];
int n,m;
void Update(int pos, int val)
{
while(pos <=n )
{
AIB[pos] += val;
pos += (pos &- pos);
}
}
int Query(int pos)
{
int sum = 0;
while( pos )
{
sum += AIB[pos];
pos -=( pos &- pos);
}
return sum;
}
int BinarySearch(int s, int d, int val){
if( s > d )
{
return -1;
}
int mid = s + (d-s)/2;
int aux = Query(mid);
if(aux == val)
return mid;
if(val < aux)
return BinarySearch(s, mid-1, val);
return BinarySearch(mid+1, d, val);
}
int Query1(int val)
{
int i,j;
return BinarySearch(1,n,val);
}
void Read()
{
int i,j,t,a,b,x;
fin>>n>>m;
for(i=1; i<=n; ++i)
{
fin>>x;
Update(i,x);
}
for(i=1; i<=m; ++i)
{
fin>>t>>a;
if(t == 0)
{
fin>>b;
Update(a,b);
}
if(t == 1)
{
fin>>b;
fout<<Query(b) - Query(a-1)<<"\n";
}
if(t == 2)
{
fout<<Query1(a)<<"\n";
}
}
}
int main()
{
Read();
return 0;
}