Sriver @ 2021-11-10 23:12:22
import java.io.BufferedInputStream;
import java.util.Scanner;
import java.util.Stack;
public class Main {
public static int n;
public static int[] x;
public static int[] y;
public static long result = 0;
public static void msort(int left, int right) {
int mid = (left + right) / 2;
if(left == right) {
return;
}
else {
msort(left, mid);
msort(mid+1, right);
}
int i = left;
int j = mid + 1;
int yy = left;
while(i <= mid && j <= right) {
if(x[i] > x[j]) {
result += mid - i + 1;
y[yy] = x[j];
yy++;
j++;
}
else {
y[yy] = x[i];
yy++;
i++;
}
}
while(i <= mid) {
y[yy] = x[i];
yy++;
i++;
}
while(j <= right) {
y[yy] = x[j];
yy++;
j++;
}
for(int ii = left; ii <= right; ii++) {
x[ii] = y[ii];
}
return;
}
public static void main(String args[]) {
Scanner in = new Scanner(new BufferedInputStream(System.in));
n = in.nextInt();
x = new int[n+1];
y = new int[n+1];
for(int i = 1; i <= n; i++) {
x[i] = in.nextInt();
}
msort(1, n);
System.out.println(result);
in.close();
}
}
求大佬指点Java代码该怎么优化呀呜呜呜呜
by 镜音铃 @ 2021-11-10 23:28:28
洛谷评测机就是歧视虚拟机语言
by Sriver @ 2021-11-11 18:31:02
@镜音铃 怎么办,实际上ccf或者蓝桥这种暴力比赛这种情况会好一些么大佬555555