title: Appearance of characters in substrings
body: <p>Given an S string of characters, write a program that responds correctly if character C appears in the substring of S that starts at position I and has length T.</p>
  
  <p>entry<br>
  The S string formed of alphanumeric characters and of length at most 1,000,000. Subsequently an integer N followed by N triplets C, I, T. You can assume that 1≤N≤10,000 that 0≤I &lt;| S | and 1≤T≤ | S | -I.</p>
  
  <p>exit<br>
  For each question, a line with a 1 if the character appears in the indicated substring and 0 otherwise.</p>
  
  <p>My idea was to implement a binary search but the judge that qualifies it says that it goes beyond the expected time and I do not know how to optimize it to the degree that the judge accepts my algorithm. For example, an entry could be:</p>
  
  <pre><code>how are you
  3
  h 0 3
  1
  o 2 5
  1
  a 4 4
  0 
  </code></pre>
  
  <p>My code:</p>
  
  <pre class="lang-c prettyprint-override"><code>#include &lt;stdio.h&gt;
  #include &lt;string.h&gt;
  
  int busqcadena(char cadena[], int a[],char x,int pos,int n);
  
  int main()
  {
      char cadena[1000000]; 
      char c;
      int t = 0, i; 
      int pos, lon, a[1000000], j = 0;
      do{
          fflush(stdin);
          c = getchar();
          cadena[i++] = c;
          a[j] = j;
          j++;
      } while (c != '\n');
      cadena[ i - 1 ] = '\0'; 
  
      scanf("%d",&amp;t);
      for( int k = 0; k &lt; t; k++){
      char pa; pos = 0; lon = 0;
      scanf("%s %d %d",&amp;pa, &amp;pos, &amp;lon);
      int busq3 = busqcadena(cadena,a,pa,pos,lon);
      if( busq3 != -1){
          printf("1\n");
      }else{
          printf("0\n");
      } 
  }
      return 0; 
  }
  
  int busqcadena(char cadena[], int arr[],char x,int pos,int n){
      int a = 0, b = n - 1;
      while( a &lt;= b ){
          int k = (a+b)/2;
          if( cadena[k] == x &amp;&amp; arr[k] == pos){
              return arr[k]; 
          }
          if( arr[k] &gt; pos ) b = k - 1;
          else a = k + 1;
      }
      return -1;
  }
  </code></pre>