Summation of Arithmetic Progression Modulo Series
Don't use underscore as a prefix. In most situations this is a reserved identifier. Defiantly never use double underscore in an identifier. This is reserved in all situations.

__argc  /// This is so wrong. It will break.


Read a couple of other C++ reviews. They all explain why this is a bad idea:

using namespace std;


This is not old school C. You don't need to declare the variables at the top of the function.

long N, Q, *boxes;


Declare them as close to the point of use as possible. This becomes important when your types have constructor/destructor (as they execute code). But it also makes the code easier to read as the type information is close to the usage of the object.

Please declare one variable per line (easier to read).

long    N;
long    Q;
long*   boxes; // The * belongs close to the type (as it is part of the type info).
               // PS you probably should not be using pointers. In modern C++ they
               // are vanishingly rare (as there is no ownership semantics associated
               // with a pointer).


Don't do this.

std::ifstream* infile = !filepath.empty() ? new std::ifstream(filepath.c_str()) : static_cast&lt;std::ifstream*&gt;(&amp;std::cin)


Should I call delete on this? Yes if it is a file. No if it is std::cin. So not a good solution. Also std::cin is not a file stream so casting it is going to do nasty things. You should never cast things (it means you have something wrong with your design (or you are working at very low level (which most people should not be doing))).

But they are both std::istream. So you could do this.

std::ifstream   file;
if (!filepath.empty()) {
    file.open(filepath);       // Modern C++ allows std::string here.
}

std::istream&amp; infile = !filepath.empty()
                             ? file 
                             : std::cin;


You may want to check that the read works:

*infile &gt;&gt; N &gt;&gt; Q;


Very easily done with:

if (infile &gt;&gt; N &gt;&gt; Q) {
    // Read was good.
    // Do stuff.
}


Main is special. So does not need a return code.

return 0;


So if your application never fails (ie always returns 0). Use this info. A missing return in main is an indication that the application never fails.