Cod sursa(job #1899632)

Utilizator medicinedoctoralexandru medicinedoctor Data 2 martie 2017 20:47:12
Problema Arbori indexati binar Scor 40
Compilator cpp Status done
Runda Arhiva educationala Marime 0.78 kb
#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";
        }
    }
}