HDU4791(线段树+二分)
来源:互联网 发布:上海口腔网络咨询招聘 编辑:程序博客网 时间:2024/05/16 16:13
#include <cstdio>#include <cstring>#include <cmath>#include <iostream>#include <algorithm>using namespace std;#define maxn 111111#define INF 1000000009#define pl c<<1#define pr (c<<1)|1#define lson tree[c].l,tree[c].mid,c<<1#define rson tree[c].mid+1,tree[c].r,(c<<1)|1int n, m;long long s[maxn], p[maxn];long long q;struct node { int l, r, mid; long long num;}tree[maxn<<4];void build_tree (int l, int r, int c) { tree[c].l = l, tree[c].r = r, tree[c].mid = (l+r)>>1; if (l == r) { tree[c].num = s[r+1]*p[r+1]; return ; } build_tree (lson); build_tree (rson); tree[c].num = min (tree[pl].num, tree[pr].num);}long long query (int l, int r, int c, int x, int y) { long long ans = 0; if (x == l && y == r) { ans = tree[c].num; return ans; } else if (y <= tree[c].mid) { return query (lson, x, y); } else if (x > tree[c].mid) { return query (rson, x, y); } else return min (query (lson, x, tree[c].mid), query (rson, tree[c].mid+1, y));}int main () { int t; scanf ("%d", &t); while (t--) { scanf ("%d%d", &n, &m); for (int i = 1; i <= n; i++) { scanf ("%lld%lld", &s[i], &p[i]); } if (n > 1) build_tree (1, n-1, 1); for (int i = 1; i <= m; i++) { scanf ("%lld", &q); int pos = upper_bound (s+1, s+1+n, q) - s; pos--; if (pos == n) { printf ("%lld\n", p[pos]*q); continue; } else printf ("%lld\n", min (p[pos]*q, query (1, n-1, 1, pos, n-1))); } } return 0;}/*103 100 20 100 10 200 155 100 5*/
0 0
- HDU4791(线段树+二分)
- HDU4791->贪心&&二分优化
- HDU4791——Alice's Print Service(线段树)
- hdu3564(二分+线段树)
- hdu4614 二分+线段树
- hdu5217Brackets【线段树,二分】
- 【HDU4614】【线段树】【二分】
- HDU5592(线段树+二分)
- Codeforces460C【二分+线段树】
- hdu6070 二分+线段树
- HDU6070 二分 线段树
- hdu6070 线段树+二分
- UVA12663 线段树+二分
- poj2182 线段树/线段数组+二分搜索
- hdu 4339 线段树+二分
- hdu 4614 线段树+二分~
- HDU 4614 线段树+二分
- HDU 4791二分+线段树
- 对MapReduce的简单理解以及归纳总结
- Nginx 1.5.2 + PHP 5.5.1 + MySQL 5.6.10 在 CentOS 下的编译安装
- [BZOJ1614][Usaco2007 Jan]Telephone Lines架设电话线
- Windows 通过命令行设置环境变量
- My coding way (2)
- HDU4791(线段树+二分)
- android listview 使用代码滚动到指定位置(标记)
- poj 3276 翻转牛的朝向
- UVa10763--Foreign Exchange(水题)
- 我的技术栈
- 下载还要积分,我来发一篇文章混一个积分
- programming-challenges Weights and Measures (111103) 题解
- leetcode14 Longest Common Prefix
- layer js web弹窗、层