博客
关于我
谜一样的牛
阅读量:230 次
发布时间:2019-02-28

本文共 1480 字,大约阅读时间需要 4 分钟。

?n????????????1?n?????????????????????????????????

????

?????????????????????????????????????Fenwick Tree??????????????????????????

???????

  • ???????????????1????????????
  • ?????????????????????
  • ?????????????????????????????
  • ?????????????????????????????????
  • ????

    #include 
    #include
    #include
    using namespace std;int lowbit(int x) { return x & -x;}void add(int x, int c, int n, vector
    & tr) { while (x <= n) { tr[x] += c; x += lowbit(x); }}int sum(int x, int n, const vector
    & tr) { int res = 0; while (x > 0) { res += tr[x]; x -= lowbit(x); } return res;}int main() { int n; vector
    a(n + 1); for (int i = 2; i <= n; ++i) { a[i] = 0; } for (int i = 1; i <= n; ++i) { int val; scanf("%d", &val); a[i] = val; } vector
    tr(n + 1, 1); // ???????????????1 vector
    ans(n + 1); for (int i = n; i >= 1; --i) { int k = a[i] + 1; int l = 1, r = n; while (l < r) { int mid = (l + r + 1) / 2; int s = sum(mid, n, tr); if (s >= k) { r = mid; } else { l = mid; } } ans[i] = l; add(l, -1, n, tr); } for (int i = 1; i <= n; ++i) { printf("%d\n", ans[i]); } return 0;}

    ????

  • lowbit????????????????????????????
  • add????????????????????????
  • sum??????????????????????????????????
  • ????
    • ?????????????
    • ?????????????????????
    • ???????????????????????
    • ?????????
  • ?????????????????????????????????

    转载地址:http://satn.baihongyu.com/

    你可能感兴趣的文章
    Object c将一个double值转换为时间格式
    查看>>
    object detection错误之Could not create cudnn handle: CUDNN_STATUS_INTERNAL_ERROR
    查看>>
    Object of type 'ndarray' is not JSON serializable
    查看>>
    Object Oriented Programming in JavaScript
    查看>>
    OBJECTIVE C (XCODE) 绘图功能简介(转载)
    查看>>
    Objective-C——判断对象等同性
    查看>>
    Objective-C之成魔之路【7-类、对象和方法】
    查看>>
    Objective-C享元模式(Flyweight)
    查看>>
    Objective-C以递归的方式实现二叉搜索树算法(附完整源码)
    查看>>
    Objective-C内存管理教程和原理剖析(三)
    查看>>
    Objective-C实现 Greedy Best First Search最佳优先搜索算法(附完整源码)
    查看>>
    Objective-C实现 jugglerSequence杂耍者序列算法 (附完整源码)
    查看>>
    Objective-C实现1000 位斐波那契数算法(附完整源码)
    查看>>
    Objective-C实现2 个数字之间的算术几何平均值算法(附完整源码)
    查看>>
    Objective-C实现2d 表面渲染 3d 点算法(附完整源码)
    查看>>
    Objective-C实现2D变换算法(附完整源码)
    查看>>
    Objective-C实现3n+1猜想(附完整源码)
    查看>>
    Objective-C实现3n+1猜想(附完整源码)
    查看>>
    Objective-C实现9x9乘法表算法(附完整源码)
    查看>>
    Objective-C实现9×9二维数组数独算法(附完整源码)
    查看>>