Pagini recente » Cod sursa (job #1396460) | Cod sursa (job #37900) | Cod sursa (job #2539028) | Cod sursa (job #2934965) | Cod sursa (job #2911639)
/******************************************************************************
Welcome to GDB Online.
GDB online is an online compiler and debugger tool for C, C++, Python, Java, PHP, Ruby, Perl,
C#, OCaml, VB, Swift, Pascal, Fortran, Haskell, Objective-C, Assembly, HTML, CSS, JS, SQLite, Prolog.
Code, Compile, Run and Debug online from anywhere in world.
*******************************************************************************/
#include <fstream>
using namespace std;
ifstream cin("aib.in");
ofstream cout("aib.out");
const int NMAX = 100001;
int v[NMAX], n;
long long AIB[NMAX];
void set(int i, int val){
while(i<=n){
AIB[i] += val;
i += i & (-i);
}
}
long long sum1(int i, int j){
long long sum=0;
i--;
while(j>i){
sum+=AIB[j];
j-=j&(-j);
}
while(i>j){
sum-=AIB[i];
i-=i&(-i);
}
return sum;
}
long long suma(int i){
long long sum=0;
while(i>0){
sum += AIB[i];
i -= i & (-i);
}
return sum;
}
int ret(int val){
int i, step;
for ( step = 1; step < n; step <<= 1 );
for( i = 0; step; step >>= 1 )
{
if( i + step <= n)
{
if( val >= AIB[i+step] )
{
i += step, val -= AIB[i];
if ( !val ) return i;
}
}
}
return -1;
}
int main()
{
cin>>n;
int q;
cin>>q;
for(int i=1; i<=n; i++){
cin>>v[i];
}
for(int i=1; i<=n; i++){
set(i, v[i]);
}
for(int t=0; t<q; t++){
int a;
cin>>a;
if(a==0){
int x, y;
cin>>x>>y;
set(x, y);
//cout<<0;
}
else if(a==1){
int x, y;
cin>>x>>y;
cout<<sum1(x, y)<<endl;
//cout<<1;
}
else{
int x;
cin>>x;
cout<<ret(x)<<endl;
}
}
return 0;
}