title: O(log n) Programming
body: <p>I am trying to prepare for a contest but my program speed is always dreadfully slow as I use O(n). First of all, I don't even know how to make it O(log n), or I've never heard about this paradigm. Where can I learn about this?</p>
  
  <p>For example,</p>
  
  <p>If you had an integer array with zeroes and ones, such as [ 0, 0, 0, 1, 0, 1 ], and now you wanted to replace every 0 with 1 <strong>only if one of it's neighbors</strong> has the value of 1, what is the most efficient way to go about doing if this must occur t number of times? (The program must do this for a number of t times)</p>
  
  <p>EDIT:
  Here's my inefficient solution:</p>
  
  <pre><code>import java.util.Scanner;
  
  public class Main {
  
  static Scanner input = new Scanner(System.in);
  
  public static void main(String[] args) {
  
      int n;
      long t;
  
      n = input.nextInt();
      t = input.nextLong();
      input.nextLine();
  
      int[] units = new int[n + 2];
      String inputted = input.nextLine();
      input.close();
      for(int i = 1; i &lt;= n; i++) {
          units[i] = Integer.parseInt((""+inputted.charAt(i - 1)));
      }
  
      int[] original;
  
      for(int j = 0; j &lt;= t -1; j++) {
          units[0] = units[n];
          units[n + 1] = units[1];
          original = units.clone();
  
          for(int i = 1; i &lt;= n; i++) {
              if(((original[i - 1] == 0) &amp;&amp; (original[i + 1] == 1)) || ((original[i - 1] == 1) &amp;&amp; (original[i + 1] == 0))) {
                  units[i] = 1;
              } else {
                  units[i] = 0;
              }
          }
  
      }
  
      for(int i = 1; i &lt;= n; i++) {
          System.out.print(units[i]);
      }
  }
  </code></pre>
  
  <p>}</p>