Pagini recente » Cod sursa (job #846727) | Cod sursa (job #67334) | Cod sursa (job #1759644) | Cod sursa (job #693865) | Cod sursa (job #3214870)
#include <fstream>
#include <vector>
#include <queue>
using namespace std;
using pii = pair<int,int>;
const int nmax = 1e5 + 1;
ifstream cin("aib.in");
ofstream cout("aib.out");
int x , bit[nmax] , n , m , op , a , b;
void upd(int x , int &val)
{
for(; x<=n ; x+=(x&-x)) bit[x] += val;
}
long long qry(int x)
{
long long sum = 0;
for(; x>0 ; x-=(x&-x)) sum += bit[x];
return sum;
}
signed main()
{
cin >> n >> m;
for(int i = 1 ; i <= n ; ++i)
{
cin >> x;
upd(i,x);
}
for(int i = 1 ; i <= m ; ++i)
{
cin >> op >> a;
if(!op)
{
cin >> b;
upd(a,b);
}
if(op&1)
{
cin >> b;
cout << qry(b) - qry(a-1) << '\n';
}
if(op==2)
{
int st = 1 , dr = n , ans = -1;
while(st <= dr)
{
int mj = st + (dr-st)/2;
if(qry(mj) >= a)
{
ans = mj;
dr = mj - 1;
}
else st = mj + 1;
}
if(ans == -1)
{
cout << -1;
}
else if(qry(ans) != a)
{
cout << -1;
}
else cout << ans;
cout << '\n';
}
}
return 0;
}