Pagini recente » Cod sursa (job #44830) | Cod sursa (job #1544900) | Cod sursa (job #357897) | Cod sursa (job #2072413) | Cod sursa (job #422052)
Cod sursa(job #422052)
//#include <iostream>
#include <fstream>
using namespace std;
ifstream cin("aib.in");
ofstream cout("aib.out");
long int n, *c, k;
void add(long int x, long int y)
{
while (x <= n)
{
c[x] += y;
int pos = 0;
while ((x & (1 << pos)) == 0) ++pos;
x += (1 << pos);
++pos;
}
}
long int interog(long int x, long int y)
{
if (x != 1) return interog(1, y) - interog(1, x - 1);
long int sum = 0;
while (y > 0)
{
sum += c[y];
int pos = 0;
while ((y & (1 << pos)) == 0) ++pos;
y -= (1 << pos);
++pos;
}
return sum;
}
int main()
{
long int x, y, z, t;
int tm;
cin >> n >> t;
c = new long int[n + 1];
for (int i = 1; i <= n; ++i)
{
cin >> x;
add(i, x);
};
for (int i = 0; i < t; ++i)
{
cin >> x;
if (x == 0)
{
cin >> y >> z;
add(y, z);
}
if (x == 1)
{
cin >> y >> z;
cout << interog(y, z) << endl;
}
if (x == 2)
{
cin >> y; tm = 0;
for (k = 1; i <= n; ++k)
{
if (interog(1, k) == y) break;
}
if (k == n + 1) k = -1;
cout << k << endl;
}
}
cin.close();
cout.close();
return 0;
}