博客
关于我
谜一样的牛
阅读量: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/

    你可能感兴趣的文章
    Netty工作笔记0050---Netty核心模块1
    查看>>
    Netty工作笔记0084---通过自定义协议解决粘包拆包问题2
    查看>>
    Netty常见组件二
    查看>>
    netty底层源码探究:启动流程;EventLoop中的selector、线程、任务队列;监听处理accept、read事件流程;
    查看>>
    Netty核心模块组件
    查看>>
    Netty框架的服务端开发中创建EventLoopGroup对象时线程数量源码解析
    查看>>
    Netty源码—2.Reactor线程模型一
    查看>>
    Netty源码—4.客户端接入流程一
    查看>>
    Netty源码—4.客户端接入流程二
    查看>>
    Netty源码—5.Pipeline和Handler一
    查看>>
    Netty源码—6.ByteBuf原理二
    查看>>
    Netty源码—7.ByteBuf原理三
    查看>>
    Netty源码—7.ByteBuf原理四
    查看>>
    Netty源码—8.编解码原理二
    查看>>
    Netty源码解读
    查看>>
    Netty的Socket编程详解-搭建服务端与客户端并进行数据传输
    查看>>
    Netty相关
    查看>>
    Network Dissection:Quantifying Interpretability of Deep Visual Representations(深层视觉表征的量化解释)
    查看>>
    Network Sniffer and Connection Analyzer
    查看>>
    NFS共享文件系统搭建
    查看>>