import java.util.*;

/**
 * Class BooleanStateArray tracks the boolean state
 * corresponding to a list of int keys provided in
 * the class constructor.
 */
public class BooleanStateArray
{
    private int[] keys = null;
    
    private boolean[] states = null;
    
    
    /**
     * Initializes the BooleanStateArray with the list
     * of keys whose boolean state will be maintained.
     * 
     * This list cannot be changed after construction.
     */
    public BooleanStateArray(int ... list) {
        int N = 0;
        
        if (list == null)
            keys = new int[0];
        else {
            N = list.length;
            
            keys = new int[N];
            
            for (int i = 0; i < N; i++)
                keys[i] = list[i];
        }
        
        Arrays.sort(keys);
        
        int duplicates = 0;
        
        for (int i = 1; i < N; i++)
            if (keys[i] == keys[i-1])
                duplicates++;
        
        if (duplicates > 0) {
            int M = N - duplicates;
            int[] copy = new int[M];
            
            copy[0] = keys[0];
            
            int k = 1;
            
            for (int i = 1; i < N; i++) {
                if (keys[i] != keys[i-1]) {
                    copy[k] = keys[i];
                    k++;
                }
            }
            
            N = M;
            keys = copy;
        }
        
        states = new boolean[N];
    }
    
    
    /**
     * Returns the boolean state of the given key.
     * 
     * Returns false if the key was not given in
     * the list provided to the constructor.
     */
    public boolean getState(int key) {
        int index = Arrays.binarySearch(keys, key);
        
        if (index >= 0)
            return states[index];
        else
            return false;
    }
    
    
    /**
     * Sets the boolean state of the given key.
     * 
     * Does nothing if the key was not given in
     * the list provided to the constructor.
     */
    public void setState(int key, boolean state) {
        int index = Arrays.binarySearch(keys, key);
        
        if (index >= 0)
            states[index] = state;
    }
    
}
