Language: C++

Not able to solve this problem during the contest (virtual participation).

The first observation is that if we can identify N−1 balls of which half is blue and the other half is red, then with these N−1 balls we can identify the color of the rest N+1 balls.

It's not hard to note that if there are more blue balls than red balls among balls numbered from l to l+N−1 but less among balls numbered from l+1 to l+N, we then know that

The l-th ball and the l+N-th ball must be of different colors.
The l-th ball must be blue and the l+N-th ball must be red.
There are equal number of blue and red balls among balls numbered from l+1 to l+N−1.
The problem is whether such l even exists? The answer is ,fortunately, YES.

Here comes the second interesting observation:
Let's assume without loss of generality, there are more blue balls than red balls among the first N balls, then there must be more red balls among the last N balls. So such l as described above must exist, and we can find one using binary search which costs at most log2N+1 queries. When the binary search finishes, we get l and the color of the l-th and l+N-th balls.

When l is found, for each ball numbered from 1 to l−1 or from l+N+1 to 2N, we can know its color with a query. Note that exactly half of these N−1 known balls are blue, so we can use these balls to identify color of balls numbered from l+1 to l+N−1 in a similar way.

Compiler output:
a.cc:3:50: error: extended character − is not valid in an identifier
    3 | The first observation is that if we can identify N−1 balls of which half is blue and the other half is red, then with these N−1 balls we can identify the color of the rest N+1 balls.
      |                                                  ^
a.cc:3:125: error: extended character − is not valid in an identifier
    3 | The first observation is that if we can identify N−1 balls of which half is blue and the other half is red, then with these N−1 balls we can identify the color of the rest N+1 balls.
      |                                                                                                                             ^
a.cc:5:3: warning: missing terminating ' character
    5 | It's not hard to note that if there are more blue balls than red balls among balls numbered from l to l+N−1 but less among balls numbered from l+1 to l+N, we then know that
      |   ^
a.cc:5:3: error: missing terminating ' character
    5 | It's not hard to note that if there are more blue balls than red balls among balls numbered from l to l+N−1 but less among balls numbered from l+1 to l+N, we then know that
      |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:9:81: error: extended character − is not valid in an identifier
    9 | There are equal number of blue and red balls among balls numbered from l+1 to l+N−1.
      |                                                                                 ^
a.cc:13:4: warning: missing terminating ' character
   13 | Let's assume without loss of generality, there are more blue balls than red balls among the first N balls, then there must be more red balls among the last N balls. So such l as described above must exist, and we can find one using binary search which costs at most log2N+1 queries. When the binary search finishes, we get l and the color of the l-th and l+N-th balls.
      |    ^
a.cc:13:4: error: missing terminating ' character
   13 | Let's assume without loss of generality, there are more blue balls than red balls among the first N balls, then there must be more red balls among the last N balls. So such l as described above must exist, and we can find one using binary search which costs at most log2N+1 queries. When the binary search finishes, we get l and the color of the l-th and l+N-th balls.
      |    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:15:51: error: extended character − is not valid in an identifier
   15 | When l is found, for each ball numbered from 1 to l−1 or from l+N+1 to 2N, we can know its color with a query. Note that exactly half of these N−1 known balls are blue, so we can use these balls to identify color of balls numbered from l+1 to l+N−1 in a similar way.
      |                                                   ^
a.cc:15:144: error: extended character − is not valid in an identifier
   15 | When l is found, for each ball numbered from 1 to l−1 or from l+N+1 to 2N, we can know its color with a query. Note that exactly half of these N−1 known balls are blue, so we can use these balls to identify color of balls numbered from l+1 to l+N−1 in a similar way.
      |                                                                                                                                                ^
a.cc:15:246: error: extended character − is not valid in an identifier
   15 | When l is found, for each ball numbered from 1 to l−1 or from l+N+1 to 2N, we can know its color with a query. Note that exactly half of these N−1 known balls are blue, so we can use these balls to identify color of balls numbered from l+1 to l+N−1 in a similar way.
      |                                                                                                                                                                                                                                                      ^
a.cc:1:1: error: 'Not' does not name a type
    1 | Not able to solve this problem during the contest (virtual participation).
      | ^~~