2017年4月15日
今天学习了线段树两题。
训练指南的uvalive 3938\http://paste.ubuntu.com/24387212/
leetcode
315. Count of Smaller Numbers After Self

struct Node
{int s;
};
vector<Node> tree;
int mid(int l, int r)
{return l + (r - l) / 2;
}
void build(int o, int l, int r)
{if (l == r) {tree[o].s = 0;return;}int m = mid(l, r), lc = o * 2, rc = o * 2 + 1;build(lc, l, m);build(rc, m+1, r);tree[o].s = tree[lc].s + tree[rc].s;
}
int query(int o, int l, int r, int qr)
{if (qr == 0) return 0;if (r == qr) return tree[o].s;int m = mid(l, r), lc = o*2, rc = o*2+1;if (m >= qr) return query(lc, l, m, qr);return tree[lc].s + query(rc, m + 1, r, qr);
}
void update(int o, int l, int r, int v)
{int m = mid(l, r), lc = o*2, rc = o*2 + 1;if (l == r) {tree[o].s++; return;}if (v <= m) update(lc, l, m, v); else update(rc, m+1, r, v);tree[o].s = tree[lc].s + tree[rc].s;
}class Solution {
public:vector<int> countSmaller(vector<int>& nums) {map<int, int> f, ff;int n = nums.size();vector<int> ans(n);if (n == 0) return ans;int a[n];tree.resize(4 * n);for (int i = 0; i < n; i++) {scanf("%d", &nums[i]);a[i] = nums[i];}sort(a, a + n);int nn = unique(a, a + n) - a;for (int i = 0; i < nn; i++) {f[a[i]] = i + 1;ff[i + 1] = a[i];}build(1, 1, nn);for (int i = n - 1; i >= 0; i--) {ans[i] = query(1, 1, n, f[nums[i]] - 1);update(1, 1, n, f[nums[i]]);}return ans;}
};

已经11点45了,不过我不编程,好像也没有什么别的事情可以干。
GO HOME!

2017年4月15日相关推荐

  1. python pandas dataframe 行列选择,切片操作 原创 2017年02月15日 21:43:18 标签: python 30760 python pandas dataframe

    python pandas dataframe 行列选择,切片操作 原创 2017年02月15日 21:43:18 标签: python / 30760 编辑 删除 python pandas dat ...

  2. 2017年1月15日 星期日 --出埃及记 Exodus 22:5

    2017年1月15日 星期日 --出埃及记 Exodus 22:5 "If a man grazes his livestock in a field or vineyard and let ...

  3. 2017年8月15日 星期二

    2017年8月15日 星期二

  4. 2017年7月15日 星期六 --出埃及记 Exodus 28:6

    2017年7月15日 星期六 --出埃及记 Exodus 28:6 "Make the ephod of gold, and of blue, purple and scarlet yarn ...

  5. 2017年12月15日区块链沙龙视频回放(1)

    很多小伙伴由于各种原因没能第一时间参加我们的沙龙,向我询问12月15日区块链沙龙的具体内容. 本周CSDN将陆续放出"12月15日区块链沙龙"的讲师演讲视频内容,没参会的.想回顾下 ...

  6. win10安装IIS时报错windows无法请求的更改,错误代码0x8007057解决办法2017年10月15日

    最近准备学习ASP.net但是发现安装IIS老是提示windows无法请求的更改,我是win10内部版本1607家庭中文版64位,在启用或者关闭windows功能安装IIS就这个安装不上,像TFTP客 ...

  7. 2017年 1月 15日 指针 学习整理

    有关指针的概念: 指针是一个特殊的变量,它里面存储的数值被解释为内存里的一个地址. FIrst of all:我们需要明确目标 关于指针的学习以及使用我们需要搞清楚有关指针的四个内容:指针的类型,指针 ...

  8. 传智168期JavaEE struts2杜宏 day32~day33(2017年2月15日23:27:09)

    struts2学习完毕,寒假学习效率还不错. 笔记链接 链接:http://pan.baidu.com/s/1boBJLVp 密码:wwl4 转载于:https://www.cnblogs.com/h ...

  9. 传智168期 SSH网上商城笔记day41~day45(2017年4月15日15:57:30)

    SSH网上商城,笔记只是简略的,主要记录一些注意事项. 链接:http://pan.baidu.com/s/1slO2aHv 密码:3huf 转载于:https://www.cnblogs.com/h ...

最新文章

  1. 敏捷之父Martin Fowler作序推荐《演进式架构》
  2. 查看提交历史 —— Git 学习笔记 11
  3. 为什么说下一个十年的主战场在Serverless?
  4. vmware下ubuntu重启后不能上网
  5. 电脑故障维修判断指导大全(5)
  6. 淘宝网架构分享总结[转]
  7. nginx 405 not allowed问题解决方法
  8. python爬虫课程设计摘要_爬虫课程设计(爬虫代码)
  9. 机器学习——Gradient Boost Decision Tree(Treelink)
  10. win10+64位 安装Theano并实现GPU加速
  11. OSX: Scripts,让BootCamp在不论什么Mac上支持生成Windows7的USB安装盘
  12. 启天m7300微型计算机,启天M7300
  13. 新浪邮箱接收服务器,新浪和雅虎的邮箱的接收服务器分别是什么?
  14. ISO8601标准时间格式
  15. BI神器Power Query(3)-- PQ从表格导入数据
  16. [MongoDB] 按时间分组统计(任意时间段)
  17. 滑动窗口大杀器,牛逼
  18. 大学生日记 我走出了农村 却永远走不进城市
  19. 哈姆雷特的机器人可以合体吗_饥荒哈姆雷特机器人wx-78怎么样 机器人wx-78人物属性详解...
  20. Matlab求解非线性规划

热门文章

  1. 【nowcoder 225278】牛牛嚯可乐(dfs)
  2. DevOps基础-5.3-持续交付:持续交付流水线
  3. 突击Mercurial SCM(HG)13---回退到指定版本
  4. hadoop国内镜像下载
  5. java cast是什么意思啊_Java Class.cast()与cast操作符
  6. Python中几个实用且有趣的函数
  7. 腾讯-产品经理能力模型(转)
  8. 极度未知HyperX Cloud Alpha Wireless 0束缚长续航电竞耳机
  9. 互联网时代的改变,零食品牌崛起,传统零食产业如何“逆袭”?
  10. 计算机协会活动策划,大学计算机协会活动计划书