Pagini recente » Cod sursa (job #2928221) | Cod sursa (job #1352467) | Cod sursa (job #29201) | Cod sursa (job #1680607) | Cod sursa (job #1449012)
#define REP(a,b) for(int a=0; a<(b); ++a)
#define FWD(a,b,c) for(int a=(b); a<(c); ++a)
#define FWDS(a,b,c,d) for(int a=(b); a<(c); a+=d)
#define BCK(a,b,c) for(int a=(b); a>(c); --a)
#define ALL(a) (a).begin(), (a).end()
#define SIZE(a) ((int)(a).size())
#define VAR(x) #x ": " << x << " "
#define FILL(x,y) memset(x,y,sizeof(x))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define MAX(a,b) (((a)>(b))?(a):(b))
#define x first
#define y second
#define st first
#define nd second
#define pb push_back
#define nleft (n<<1)
#define nright (nleft+1)
#define lsb(a) (a&-a)
#include<vector>
using namespace std;
#include<fstream>
ifstream cin("aib.in");
ofstream cout("aib.out");
const int NMAX = 101001;
const int INF = 0x3f3f3f3f;
const int dx[] = {0,0,-1,1}; //1,1,-1,1};
const int dy[] = {-1,1,0,0}; //1,-1,1,-1};
typedef long long LL;
typedef pair<int, int> PII;
typedef long double K;
typedef pair<K, K> PKK;
typedef vector<int> VI;
int m,i,j,a,b,c;
class Bit{
public:
int n;
int A[NMAX];
void update(int i, int x)
{
while(i<=n)
{
A[i]+=x;
i+=lsb(i);
}
}
int query(int i)
{
int suma=0;
while(i)
{
suma+=A[i];
i-=lsb(i);
}
return suma;
}
int lower_binary(int val)
{
int i, step;
for(step=1;step<=n;step<<=1);
for(i=n; step; step>>=1)
if(i-step>0 && query(i-step) >= val)
i-=step;
return i;
}
};
Bit A;
int main()
{
cin>>A.n>>m;
REP(i,A.n){
cin>>a;
A.update(i+1,a);
}
while(m--)
{
cin>>a;
switch(a)
{
case 0:
cin>>b>>c;
A.update(b,c);
break;
case 1:
cin>>b>>c;
cout<<A.query(c)-A.query(b-1)<<"\n";
break;
case 2:
cin>>b;
i=A.lower_binary(b);
cout<<((A.query(i)==b)?i:-1)<<"\n";
break;
}
}
return 0;
}