Simple array operation using a Queue
I'm not really sure if your code matches the intention of the task, albeit you possibly might get the expected results.

At first, you are producing a new array, whereas the task is 'all elements raise their values', which I read that you should modify the array in place.

Then I'd rather assume that you should implement a single operation in a function which then gets called M times, example:

void applyOperation(int array[], size_t length, size_t begin, size_t end, int operator);

int array[] = { 1, 1, 1, 4, 5, 6 };
applyOperation (array, sizeof(array)/sizeof(*array), 1, 5, 2);
applyOperation (array, sizeof(array)/sizeof(*array), 2, 3, 10);
// print result


M is 2, function is called twice (I renamed N to length...).

Whether you now implement the function to execute one operation at a time or all at once, you shouldn't iterate over the entire array and then check if the index is in the range, instead you'd iterate over the range directly:

void applyOperation(int array[], size_t length, size_t begin, size_t end, int operator)
{
    --begin; --end; // they want one-based indices? bad idea for C++,
                    // but OK, then let's adjust them to zero-based...

    for(;; begin != end; ++begin)
    {
         array[begin] += operator;
    }
}


Looks much easier, doesn't it? What's actually lacking yet is checking the range of begin and end, assuming you manage this yourself...

Now if you want to have all operations in one single go, then it is much more comprehensive if you iterate over the operations in first place:

void applyOperations(int input[], int operations[], int N, int M)
{
    for(int i = 0; i &lt; M; ++i, operations += 3)
    // this assumes: each operation occupies three subsequent values
    {
         // now using operations[0] as begin, operations[1] as end
         // and operations[2] as operator just like above

         // it might be unacceptable to modify the operations array, then you'd
         // need a separate loop variable compared to above; but IF it is,
         // then you should keep the operations const anyway:
         //int const operations[]
    }
}


Finally: You tagged the question C++ &ndash; your code could as well be good old C, though. In C++, you'd rather use std::array or std::vector than raw arrays. Whichever you use, you don't have to provide size/length separately, both come with their own member function size() giving the number of elements (not size in bytes as sizeof operator does, so you'd avoid the ugly sizeof(x)/sizeof(*x) at the same time &ndash; even more important: you could provide a bad value for length, this cannot happen with the C++ containers as these manage their length/size on their own).

void applyOperation(std::vector&lt;int&gt; values, size_t begin, size_t end, int operator)
{
    --begin; --end;
    for(;; begin != end; ++begin)
    {
         values[begin] += operator;
    }
}


The loop still looks similar, but range checking would now use values.size() instead of a length parameter.

One final note: Did you notice that I changed the parameter types to size_t? Two reasons for this:


size_t is an unsigned type. Negative indices are meaningless in the given task, so why allow them at all?
size_t mapped to the native type large enough to hold an object of maximum size on given system (which means at the same time that it will always be large enough to index any member in an array). This is obviously not relevant in given case, as your arrays' sizes most likely won't ever exceed the range of ordinary int - but you simply cannot fail this way, so if you get used to it, you'll be well prepared for the future...