Pagini recente » Cod sursa (job #3139594) | Cod sursa (job #3123081) | Cod sursa (job #1013817) | Cod sursa (job #3270777) | Cod sursa (job #3198308)
#include <bits/stdc++.h>
#define eb emplace_back
#define ll long long
#define pii pair<int, int>
#define pli pair<ll, int>
#define tpl tuple<int, int, int>
#define tli tuple<ll, int, int>
using namespace std;
const string fn("aib");
ifstream in(fn + ".in");
ofstream out(fn + ".out");
#define cin in
#define cout out
const int MAX = 1e4;
int n, m, aibpoz[MAX + 5], v[MAX * 10 + 5];
ll aibsum[MAX + 5];
void upd(int poz,int val)
{
for (int i = poz; i <= MAX; i += i & -i)
aibpoz[i] += val,
aibsum[i] += val;
}
void read()
{
cin >> n >> m;
for (int i = 1; i <= n; i++)
{
cin >> v[i];
upd(i, v[i]);
}
}
ll query(int poz)
{
ll sum=0;
for(;poz>0;poz-=poz&-poz)
sum+=aibsum[poz];
return sum;
}
int binary_lifting(ll target)
{
int pos=0;
for(int p=1<<19;p;p>>=1)
if(pos+p<=n and aibsum[pos+p]<=target)
{
pos+=p,target-=aibsum[pos];
if(target==0)
return pos;
}
return -1;
}
void solve()
{
int t,a,b;
cin>>t;
if(t==0)
{
cin>>a>>b;
upd(a,b);
}
else if(t==1)
{
cin>>a>>b;
cout<<query(b)-query(a-1)<<'\n';
}
else
{
ll val;
cin>>val;
cout<<binary_lifting(val)<<'\n';
}
}
int main()
{
read();
while(m--) solve();
return 0;
}