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

    你可能感兴趣的文章
    npm.taobao.org 淘宝 npm 镜像证书过期?这样解决!
    查看>>
    npm—小记
    查看>>
    NPM使用前设置和升级
    查看>>
    npm入门,这篇就够了
    查看>>
    npm切换到淘宝源
    查看>>
    npm前端包管理工具简介---npm工作笔记001
    查看>>
    npm升级以及使用淘宝npm镜像
    查看>>
    npm发布自己的组件UI包(详细步骤,图文并茂)
    查看>>
    npm和yarn清理缓存命令
    查看>>
    npm和yarn的使用对比
    查看>>
    npm学习(十一)之package-lock.json
    查看>>
    npm安装crypto-js 如何安装crypto-js, python爬虫安装加解密插件 找不到模块crypto-js python报错解决丢失crypto-js模块
    查看>>
    npm报错Cannot find module ‘webpack‘ Require stack
    查看>>
    npm报错Failed at the node-sass@4.14.1 postinstall script
    查看>>
    npm报错unable to access ‘https://github.com/sohee-lee7/Squire.git/‘
    查看>>
    npm的安装和更新---npm工作笔记002
    查看>>
    npm的常用配置项---npm工作笔记004
    查看>>
    npm的问题:config global `--global`, `--local` are deprecated. Use `--location=global` instead 的解决办法
    查看>>
    npm编译报错You may need an additional loader to handle the result of these loaders
    查看>>
    npm设置淘宝镜像、升级等
    查看>>