Finding the largest of a series of numbers being XORed I'm working on solving a problem involving finding the largest of a series of numbers being XORed.

This is the actual problem:


  Xorq has invented an encryption algorithm which uses bitwise XOR
  operations extensively. This encryption algorithm uses a sequence of
  non-negative integers \$x_1, x_2, ... x_n\$ as key. To implement this
  algorithm efficiently, Xorq needs to find maximum value for (\$a\$ xor \$x_j\$)
  for given integers \$a\$, \$p\$ and \$q\$ such that \$p&lt;=j&lt;=q\$. Help Xorq to implement
  this function.
  
  Input
  
  First line of input contains a single integer \$T\$ (\$1 &lt;= T &lt;= 6\$). T test
  cases follow.
  
  First line of each test case contains two integers \$N\$ and \$Q\$ separated
  by a single space (\$1 &lt;= N &lt;= 100,000\$; \$1 &lt;= Q &lt;= 50,000\$). Next line contains
  \$N\$ integers \$x_1, x_2, ... x_n\$ separated by a single space (\$0 &lt;= x_i &lt; 2^{15}\$).
  Each of next Q lines describe a query which consists of three integers
  \$a_i\$, \$p_i\$ and \$q_i\$ (\$0 &lt;= a_i &lt; 2^{15}\$, \$1 &lt;= p_i &lt;= q_i &lt;= N\$).
  
  Output
  
  For each query, print the maximum value for (\$a_i\$ xor \$x_j\$) such that
  \$p_i &lt;= j &lt;= q_i\$ in a single line.


I keep failing because of a timeout.  What are some ways in which I could optimize my code to reduce time?  

Is there a better way to do the bit manipulation?  Should I be using a different data structure than an array?  I've read a few articles on optimization and changed a few things, but nothing that made a real difference.  Maybe I need to attempt the problem in a different fashion?

#include &lt;stdio.h&gt;

int main (int argc, char * argv[]) {
    unsigned int T,N,Q,i,a,p,q,count,max,n[100000],res[100000];
    scanf ("%d\n%d %d", &amp;T, &amp;N, &amp;Q);
    while (T--) {
        for (i = 0; i &lt; N; i++) {
            scanf ("%d", &amp;n[i]);
        }
        while (Q--) {
            count = 0;
            scanf ("%d %d %d", &amp;a, &amp;p, &amp;q);
            p--;
            q--;
            for (i = p; i &lt;= q; i++) {
                res[count++] = a ^ n[i];
            }
            max = res[0];
            for (i = count; i--;) {
                if (res[i] &gt; max) { 
                    max = res[i];
                }
            }
            printf ("%d\n", max);
        }
    }
    return 0;
}


I apologize for all the arbitrarily named variables.  All of these problems just use single character names as their variables.
Putting all variables of the same type onto a single line can be bad for readability and maintenance:


unsigned int T,N,Q,i,a,p,q,count,max,n[100000],res[100000];



Since the single-character variables are similar, they can still be together.  The rest of them, however, should be on separate lines.  Also, since i is a loop counter, it's best to declare it as close as possible to its for loop instead.

unsigned int T, N, Q, a, p, q;
unsigned int count;
unsigned int max;
unsigned int n[100000]
unsigned int res[100000];