POJ(2299)
来源:互联网 发布:js数组排序 编辑:程序博客网 时间:2024/05/05 16:31
#pragma warning(disable:4996)#include<cstdio>#include<cstring>#include<string>#include<cmath>#include<vector>#include<algorithm>#include<iostream>#include<time.h>using namespace std;const int INF = 0x3f3f3f3f;int a[500005];int T[500005];__int64 sum;void MergeSort(int *a, int x, int y,int *T){ if (y - x <= 1) return ; int m = x + (y - x) / 2; MergeSort(a, x, m,T); MergeSort(a, m, y,T); int p = x, q = m, i = x; while (p < m||q < y) { if (q>=y||(p<m&&a[p]<=a[q])) { T[i++] = a[p++]; } else { T[i++] = a[q++]; sum += m - p; } } for (int i = x; i <y; i++) { a[i] = T[i]; }}int main(){ int n; while (cin >> n, n) { memset(a, 0, sizeof(a)); memset(T, 0, sizeof(T)); sum = 0; for (int i = 1; i <= n; i++) { cin >> a[i]; } MergeSort(a, 1, n + 1, T); printf("%I64d\n", sum); } return 0;}
0 0
- POJ(2299)
- POJ-2299-POJ 2299
- POJ 2299(逆序对数)
- POJ 2299( Ultra-QuickSort)
- poj 2299(树状数组)
- POJ 2299 (树状数组)
- poj 2299 Ultra-QuickSort(求逆序对)&& poj 1804
- POJ 2299
- Poj 2299
- POJ 2299
- poj 2299
- poj 2299
- poj 2299
- poj.2299
- POJ 2299
- poj 2299
- poj-2299
- poj 2299
- 【多线程编程】多线程gdb调试
- 【Unity Shaders】使用Unity Render Textures实现画面特效——建立画面特效脚本系统
- 欢迎使用CSDN-markdown编辑器
- Python 安装 setuptools 和 pip
- 前端优化
- POJ(2299)
- codeforces 200D Programming Language 字符串处理
- 开启梦幻般webrtc之旅
- 【SDOI2011】染色
- Linux下查看.so和可执行文件是否debug编译
- spring与jvm 反射TypeVariable关系
- 802.11n
- CSS position:sticky
- 【Unity Shaders】使用Unity Render Textures实现画面特效——画面特效中的亮度、饱和度和对比度