Pagini recente » Cod sursa (job #1949720) | Cod sursa (job #1316937) | Cod sursa (job #2465387) | Cod sursa (job #888030) | Cod sursa (job #1899632)
#include <fstream>
#include <vector>
using namespace std;
ifstream fin ("aib.in" );
ofstream cout("aib.out");
int main()
{
int n, m, q, x, y;
vector <int> a;
fin >> n >> m;
a.resize(n);
for (int i = 0; i < a.size(); 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";
}
}
}