Pagini recente » Cod sursa (job #145619) | Cod sursa (job #2177239) | Cod sursa (job #2960046) | Cod sursa (job #143515) | Cod sursa (job #1986549)
#include <iostream>
#include <vector>
#include <fstream>
#include <algorithm>
#define ll long long
#define pb push_back
using namespace std;
ifstream fin("aib.in");
ofstream fout("aib.out");
const int NLIM = 1e5 + 10;
int N, M;
int BIT[NLIM];
void update( int i, int add )
{
while( i <= N )
{
BIT[i] += add;
i += i & ( -i );
}
}
int get( int i )
{
int ret = 0;
while( i )
{
ret += BIT[i];
i -= i & ( -i );
}
return ret;
}
int main()
{
fin >> N >> M;
for( int i = 1; i <= N; ++i )
{
int x;
fin >> x;
update( i, x );
}
while( M-- )
{
int t;
fin >> t;
if( t == 0 )
{
int a, b;
fin >> a >> b;
update( a, b );
}
else if( t == 1 )
{
int a, b;
fin >> a >> b;
fout << get( b ) - get( a - 1 ) << "\n";
}
else
{
int x;
fin >> x;
int l = 0;
int r = N - 1;
while( l <= r )
{
int m = l + ( r - l ) / 2;
if( get( m ) >= x )
r = m - 1;
else
l = m + 1;
}
if( get( l ) == x && l > 0 )
fout << l << "\n";
else
fout << -1 << "\n";
}
}
return 0;
}