@@ -0,0 +1,2340 @@
+/**%0A * Using Binary Search to Insert and Remove. So generally, the time complexity for this problem is O(nlogn)%0A * %0A */%0A%0Aimport java.util.*;%0Aimport java.text.DecimalFormat;%0Aclass Solution%7B%0A   %0A    public static void main( String args%5B%5D )%7B%0A       Solution main = new Solution();%0A       main.run();%0A       System.exit(0);%0A    %7D%0A    %0A    private void run()%7B%0A        Scanner in = new Scanner(System.in);%0A        int N = in.nextInt();%0A        ArrayList%3CLong%3E list = new ArrayList%3CLong%3E();%0A        while(N--%3E0)%7B%0A            String c = in.next();%0A            long n = in.nextLong();%0A            if(c.charAt(0) == 'a')%7B%0A                // insert it.%0A                int left = 0;%0A                int right = list.size();%0A                while(left %3C right)%7B%0A                    int mid = (left + right)/2;%0A                    if(list.get(mid) %3C= n)%7B%0A                        left = mid + 1;%0A                    %7D else%0A                        right = mid;%0A                %7D%0A                list.add(left, n);%0A                median(list);%0A            %7D else %7B%0A                int index = -1;%0A                int left = 0;%0A                int right = list.size()-1;%0A                while(left %3C= right)%7B%0A                    int mid = (left + right)/2;%0A                    long tmp = list.get(mid);%0A                    if( tmp == n)%7B%0A                        index = mid;%0A                        break;%0A                    %7D else if( tmp %3C n) %7B%0A                        left = mid + 1;%0A                    %7D else%0A                        right = mid - 1;%0A                %7D%0A                if(index == -1)%7B%0A                    System.out.println(%22Wrong!%22);%0A                %7D else %7B%0A                    list.remove(index);%0A                    median(list);%0A                %7D%0A            %7D%0A            //print(list);%0A        %7D%0A    %7D%0A    %0A    private void median(ArrayList%3CLong%3E list)%7B%0A        int N = list.size();%0A        if(N == 0)%7B%0A            System.out.println(%22Wrong!%22);%0A            return;%0A        %7D%0A        DecimalFormat format = new DecimalFormat(%220.#%22);%0A        if(N %25 2 == 0)%7B%0A            System.out.println(format.format(1.0*(list.get(N/2)+list.get(N/2-1))/2.0));%0A        %7D else %7B%0A            System.out.println(format.format(list.get(N/2)));%0A        %7D%0A    %7D%0A    private void print(ArrayList%3CLong%3E list)%7B%0A        System.out.println(list);%0A    %7D%0A%7D%0A

Add Median.java