Pagini recente » Cod sursa (job #2532131) | Cod sursa (job #578144) | Cod sursa (job #2586456) | Cod sursa (job #2440504) | Cod sursa (job #1899635)
#include <fstream>
#include <vector>
using namespace std;
ifstream fin ("aib.in" );
ofstream cout("aib.out");
int main()
{
int n, m, q, x, y, a[100000];
fin >> n >> m;
for (int i = 0; i < n; i++)
fin >> a[i];
for (int i = 0; i < m; i++)
{
fin >> q >> x;
if (q != 2) fin >> y;
if (q == 0) a[--x] += y;
if (q == 1)
{
int s = 0;
for (int i = x - 1; i < y; i++) s += a[i];
cout << s << '\n';
}
if (q == 2)
{
int s = 0, i;
for (i = 0; s < x; i++)
s += a[i];
if (s == x) cout << i << '\n';
else cout << "-1\n";
}
}
}