Couting numbers greater than given - using binary search
First, the algorithm you're using strikes me as fairly inefficient. At least if I've understood the code, your intent is to have one array of items in original order, and another in sorted order. When you get a query, you find the number at the specified position in the original array, then do a binary search to find the same item in the sorted array.

I guess if the intent is specifically to write a binary search, that's all right, but if your intent is really to carry out such queries quickly, this doesn't seem like the best approach. Instead, I'd create a more direct mapping from input position to result.

For one possible way to do this, you could create an array of pairs of input values and the position at which that value was entered:

typedef std::pair&lt;int, size_t&gt; input;

std::vector&lt;input&gt; inputs;

int temp;
size_t i = 0;

while (std::cin &gt;&gt; temp)
    inputs.emplace_back(temp, i++);


Then we can sort the inputs (preferably in descending order) based on the input number:

std::sort(inputs.begin(), inputs.end(), 
    [](input a, input b) {
        return a.first &gt; b.first;
    });


Then (the interesting part) we create our lookup table to give the result for a query directly:

std::vector&lt;size_t&gt; query_table(inputs.size());

for (int i=0; i&lt;inputs.size(); i++)
   query_table[inputs[i].second] = i;


Then handling a query is something like:

size_t query(size_t input_pos) { 
    return query_table[pos];
}


Looking at the code in your question, the first thing that sticks out is indentation (or lack thereof). In binSearch, you seem to have no indentation at all. In main, you have a little indentation, but most of your loops and such have the controlled statement on the same line as the loop header, which most C and C++ programmers find distasteful (to put it mildly).

You're also depending on using a variable length array (your int a[n]; andint a_sorted[n];`) which isn't part of C++ (though some compilers include it as an extension).

Looking specifically at the algorithm you're using for your binary search, it appears that it'll potentially give incorrect answers whenever your input contains duplicate values. It simply looks for any instance of the correct value in the sorted array, but since you only want the number of inputs that were large, it should be looking for the position of the last entry with that value. For example: if your input were [1, 2, 1, 1, 1, 1, 1, 2], the sorted array would be: [1, 1, 1, 1, 1, 1, 2, 2]. Since that has 8 elements, and the first element it looks at is the fourth, it would find the fourth, and you'd then conclude that all the other numbers were larger, so it would say there were four larger numbers. What you really want to find is the last instance of that value, so (in this case) you'd find there are really only two larger values.