hdu 5774 Bubble Sort(树状数组)
来源:互联网 发布:cygwin与linux区别 编辑:程序博客网 时间:2024/05/22 12:14
分析:
对于在位置
二个这个数字的最左边位置要么是它的起始位置,要么是它排序后的最终位置,所以它的最左边位置就是:
求
#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>#include <cmath>using namespace std;#define pr(x) cout << #x << ": " << x << " " #define pl(x) cout << #x << ": " << x << endl;struct jibancanyang{ int T, n, A[112345]; int bit[112345]; int ans[112345]; int sum(int i) { int s = 0; while (i > 0) { s += bit[i]; i -= i & -i; } return s; } void add(int i , int x) { while (i <= n) { bit[i] += x; i += i & -i; } } void fun() { scanf("%d", &T); for (int cas = 1; cas <= T; cas++) { memset(bit, 0, sizeof(bit)); scanf("%d", &n); for (int i = 1; i <= n; i++) scanf("%d", &A[i]); printf("Case #%d:", cas); for (int i = 1; i <= n; i++) { int x = sum(A[i]); int f = A[i] - 1 - x; add(A[i], 1); ans[A[i]] = i + f - min(A[i], i); } for (int i = 1; i <= n; i++) printf(" %d", ans[i]); puts(""); } }}ac;int main(){#ifdef LOCAL freopen("in.txt", "r", stdin); //freopen("out.txt", "w", stdout);#endif ac.fun(); return 0;}
0 0
- hdu 5774 Bubble Sort(树状数组)
- HDU - 5775 Bubble Sort(树状数组)
- HDU 5775 Bubble Sort(树状数组)
- HDU 5775 Bubble Sort (树状数组或线段树)
- hdu 5775 Bubble Sort 树状数组(多校)
- HDU 5775 Bubble Sort 树状数组
- 树状数组-HDU-5775-Bubble Sort
- HDU-5775-Bubble Sort-树状数组
- HDU 5775 Bubble Sort [树状数组]【数据结构】
- HDU5775 Bubble Sort树状数组
- HDU 5775 Bubble Sort 树状数组求逆序数
- hdu 5775 Bubble Sort(2016 Multi-University Training Contest 4——树状数组)
- (HDU 5775)Bubble Sort <树状数组> 多校训练4
- 多校训练-Bubble Sort(树状数组+离散化)
- hdu5755 Bubble Sort(树状数组or线段树)
- 【HDU5775】【树状数组】Bubble Sort 题解
- 2016 Multi-University Training Contest 4 hdu 5775 Bubble Sort【树状数组+思维】
- HDU 2689 Sort it (树状数组)
- cmake 生成目标三种方式
- ViewPager+Fragment LazyLoad 最优解
- 数据对象安全校验(oval框架)
- 利用gdb远程调试驱动模块
- Hadoop 入门 云计算概念
- hdu 5774 Bubble Sort(树状数组)
- IDEA 基于Spring + Spring MVC + Mybatis 高性能web构建
- JVM实用参数(八)GC日志
- spring AOP 自定义注解
- js 三种弹窗
- 近期虚拟机相关问题总结
- FFMpeg编译报错
- ubuntu 的 python从2.* 升级到3.*
- Android 多线程 线程池原理 封装线程池