CodeForces 589G Hiring(树状数组)
来源:互联网 发布:超市软件安装视频 编辑:程序博客网 时间:2024/05/29 16:26
题意:有n个工作要在m天之内完成(n,m<2e5),每个工作完成的时间由总时间r和每天的固定准备时间d(不包含在r内)构成,现在给出每天可以工作的时间,求每个工作最早完成时间。
思路:树状数组。对工作按d降序排列,每天的工作时间按降序排列,然后用两个指针扫一下,对于一个工作j来说,将工作时间大于j.d的日期全部插入到树状数组中,用树状数组维护前i天的工作时间和,还有前i天插入了多少个工作日,然后对于每个工作二分来找出最早完成时间即可。
#include<cstdio>#include<cstring>#include<cmath>#include<cstdlib>#include<iostream>#include<algorithm>#include<vector>#include<map>#include<queue>#include<stack>#include<string>#include<map>#include<set>#include<ctime>#define eps 1e-6#define LL long long#define pii pair<int, int>//#pragma comment(linker, "/STACK:1024000000,1024000000")using namespace std;const int MAXN = 200020;int n, m;LL c[MAXN], d[MAXN];int lowbit(int x) {return x&-x;}LL sumv(int x) {LL ret = 0;while(x) {ret += c[x];x -= lowbit(x);}return ret;}int cnt(int x) {int ret = 0;while(x) {ret += d[x];x -= lowbit(x);}return ret;}void update(int x, int v) {while(x <= m) {c[x] += v;d[x]++;x += lowbit(x);}} struct Node {int d, r, id;bool operator < (const Node& A) const {return d < A.d;}} node[MAXN], t[MAXN];int ans[MAXN];int main() { //freopen("input.txt", "r", stdin);cin >> n >> m;for(int i = 1; i <= m; i++) scanf("%d", &t[i].d), t[i].id = i;for(int i = 1; i <= n; i++) scanf("%d%d", &node[i].d, &node[i].r), node[i].id = i;sort(t+1, t+m+1);sort(node+1, node+n+1);int pos = m;for(int i = n; i; i--) {while(pos && t[pos].d>=node[i].d) update(t[pos].id, t[pos].d), pos--;int L = 1, R = m;while(L < R) {int M = (L+R) >> 1;if(sumv(M) >= (LL)cnt(M)*node[i].d+node[i].r) R = M;else L = M + 1;//if(i == 2) cout << M << endl;}if(R==m && sumv(R) < (LL)cnt(R)*node[i].d+node[i].r) ans[node[i].id] = 0;else ans[node[i].id] = R;} for(int i = 1; i <= n; i++) printf("%d ", ans[i]); return 0;}
0 0
- CodeForces 589G Hiring(树状数组)
- Code Forces 589G Hiring(树状数组)
- CodeForces 589G Hiring
- Codeforces 589G Hiring(BIT + 二分)
- NEERC 2015 Southern Subregional G Hiring 树状数组
- Codeforces 589G Hiring (NEERC 2015 G题)
- CF 589G 树状数组
- codeforces 191 E (树状数组+二分)
- CodeForces 301D(树状数组)
- CodeForces 594D REQ(树状数组)
- codeforces 597C (树状数组+DP)
- 树状数组(Garlands,codeforces 707e)
- codeforces 216C-Hiring Staff
- 新疆网赛G题(KMP+树状数组)
- Codeforces 276E(树状数组)
- codeforces 599C (树状数组)
- Codeforces 703D 树状数组
- codeforces 650D (树状数组)
- 一些小功能的累积
- Hibernate Merge (Illegal attempt to associate a collection with two open sessions)
- leetcode Binary Tree Zigzag Level Order Traversal
- IntelliJ Idea 常用快捷键列表
- 使用AsyncHttpClient碰到的问题及解决方法
- CodeForces 589G Hiring(树状数组)
- mysql事务回滚的问题
- 如何定制支持用户自定义boot参数的基于debian os的live cd
- POST方式上传文件
- 前端开发中的性能那点事(一)巧用xdebug
- Nginx下载和编译安装
- JS保留两位小数
- html5+javascript+css3实现下拉列表以及折叠功能
- Xrebel监控调优你的程序