title: Finding an efficient algorithm to answer queries in a submatrix of a given square matrix
body: <p>I'm trying to solving the <a href="http://www.codechef.com/DEC13/problems/RECTQUER" rel="nofollow">“Rectangular Queries” problem from the December 2013 CodeChef contest</a>:</p>
  
  <p>Given a square matrix N x N, filled with integers from {1,..10}. We are given Q(10^5) queries as follows
  given x1,y1, x2,y2 find the number of unique elements in the given sub matrix.</p>
  
  <p>Limits:
  N &lt;= 300
  Q (10^5)
  x1 &lt;= x2 &lt;= N
  y1 &lt;= y2 &lt;= N
  time limit 1 sec.</p>
  
  <p>I have tried an approach using std::set for uniqueness but getting TLE...MY approach is naive...looping from top left to bottom right for a query and adding elements to set..then printing std::set.size().</p>