二分・归并排序之逆序对

http://hihocoder.com/contest/hiho39/problems


java.util.*;

Main {
    = ;

    mergSort(List<Long> a, l, r) {
        mid;
        (l < r) {
            mid = (l + r) / ;
            (a,l, mid);
            (a, mid + , r);
           List<Long> b1,b2;
            b1 = ArrayList<Long>(a.subList(l,mid+));
            b2 = ArrayList<Long>(a.subList(mid+,r+));
            List<Long>a1 = a.subList(l,r+);
            i1=,i2=,n1=b1.size(),n2=b2.size(),i=;
            (;i1<n1&&i2<n2;){
                ( b1.get(i1)<= b2.get(i2)){
                    a1.set(i,b1.get(i1));
                    i1++;
                    i++;
                }
                {
                    a1.set(i,b2.get(i2));
                    i++;
                    +=n1-i1;
                    i2++;

                }
            }
            ( i1< n1){
                a1.set(i,b1.get(i1));
                i++;
                i1++;
            }
            ( i2< n2){
                a1.set(i,b2.get(i2));
                i++;
                i2++;
            }
        }
    }

    main(String[] args) {
        List<Long> a;
        Scanner scanner = Scanner(System.);
        a= ArrayList();
        n1 = scanner.nextInt();

        (i = ; i < n1; i++) {
            a.add(scanner.nextLong());
        }
        (a, , n1 - );
        System..println();
}

}


你可能感兴趣的:(public)