Run ID 作者 问题 语言 测评结果 分数 时间 内存 代码长度 提交时间
100802 柯昊阳 求逆序对数 C++ 通过 100 0 MS 272 KB 1021 2023-09-03 13:44:14

Tests(8/8):


#include <bits/stdc++.h> using namespace std; int arr[500005]; int tmp[500005]; long long g_sort(int left,int right){ if(left>=right) return 0; int mid = (left+right)/2; long long count1 = g_sort(left,mid); long long count2 = g_sort(mid+1,right); int i = left,j = mid+1; long long count3 = 0; int e = left; while(i<=mid&&j<=right){ if(arr[i]>arr[j]){ count3+=mid-i+1; tmp[e++] = arr[j]; j++; } else { tmp[e++] = arr[i]; i++; } } while(i<=mid){ tmp[e++] = arr[i]; i++; } while(j<=right){ tmp[e++] = arr[j]; j++; } for(int i = left;i<=right;i++) { arr[i] = tmp[i]; } return count1+count2+count3; } int main(){ int n; cin>>n; for(int i = 0;i<n;i++){ scanf("%d",&arr[i]); } long long x = g_sort(0,n-1); cout<<x<<endl; return 0; }


测评信息:

输入

                    

输出

                    

答案

                    

系统信息

exit code: 0, checker exit code: 0

输入

                    

输出

                    

答案

                    

系统信息

exit code: 0, checker exit code: 0

输入

                    

输出

                    

答案

                    

系统信息

exit code: 0, checker exit code: 0

输入

                    

输出

                    

答案

                    

系统信息

exit code: 0, checker exit code: 0

输入

                    

输出

                    

答案

                    

系统信息

exit code: 0, checker exit code: 0

输入

                    

输出

                    

答案

                    

系统信息

exit code: 0, checker exit code: 0

输入

                    

输出

                    

答案

                    

系统信息

exit code: 0, checker exit code: 0

输入

                    

输出

                    

答案

                    

系统信息

exit code: 0, checker exit code: 0