【题目链接】:http://codeforces.com/problemset/problem/589/G

【题意】



有n个人;

每个人每天在开始工作之前,都需要di单位的准备时间,然后才能开始工作;

然后每个人都有m天的时间,每天有ti个单位的时间供每个人进行准备工作以及工作;

也就是说第i个人每天必须要先扣掉di个单位的时间;剩下的才是它能够工作的时间;

然后每个人都需要完成ri个单位的时间的工作量;

然后如果你发现某一天连准备的时间都不够的话,你可以跳过这一天;

问你最早在第几天,第i个人才能够完成ri个单位的时间的工作量;

【题解】



首先把m天的时间按照时间的多少降序排;

然后把n个人,按照ri的大小降序排;

然后顺序枚举n个人;

对于每个人,维护一个指针r,这里1..r对应了哪些天是>=d[i]的;

每次r递增一个,就把它加到树状数组里面,即对应的第id天递增t[i]个单位的时间,同时记录第id天之前有多少天是满足>=d[i]的;

然后二分第i天;

看看

前i天的时间和−前i天>=d[i]天的天数∗d[i]是不是大于等于r[i];

大于等于的话就变小一点,否则变大一点;



【Number Of WA】



0

(C++11不能编译,很奇怪)



【反思】



数据结构题的话,认真想想就好.

不要着急,想好了再动手。



【完整代码】

#include <bits/stdc++.h>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ms(x,y) memset(x,y,sizeof x)
#define Open() freopen("F:\\rush.txt","r",stdin)
#define Close() ios::sync_with_stdio(0) typedef pair<int,int> pii;
typedef pair<LL,LL> pll; const int dx[9] = {0,1,-1,0,0,-1,-1,1,1};
const int dy[9] = {0,0,0,-1,1,-1,1,-1,1};
const double pi = acos(-1.0);
const int M = 2e5; struct abc{
int t,id;
}; struct person{
int d,r,id;
}; struct BIT{
pll a[M+10]; int lowbit(int x){
return x&(-x);
} void add(int x,int y){
while (x <= M){
a[x].fi+=y;
a[x].se+=1;
x+=lowbit(x);
}
} LL sum1(int x){
LL temp = 0;
while (x > 0){
temp += a[x].fi;
x-=lowbit(x);
}
return temp;
} LL sum2(int x){
LL temp = 0;
while (x > 0){
temp += a[x].se;
x-=lowbit(x);
}
return temp;
}
}; int n,m,b[M+10];
abc a[M+10];
person c[M+10];
BIT d; int main(){
//Open();
Close();
cin >> n >> m;
rep1(i,1,m){
cin >> a[i].t;
a[i].id = i;
}
sort(a+1,a+1+m,[&] (abc a,abc b){ return a.t > b.t;});
rep1(i,1,n){
cin >> c[i].d >> c[i].r;
c[i].id = i;
}
sort(c+1,c+1+n,[&] (person a,person b) {return a.d > b.d;});
int cur = 1;
rep1(i,1,n){
while (cur<=m && a[cur].t>=c[i].d){
d.add(a[cur].id,a[cur].t);
cur++;
}
int l = 0,r = m,temp = 0;
while (l <= r){
int mid = (l+r)>>1;
LL temp1 = d.sum1(mid),temp2 = d.sum2(mid);
temp1-=temp2*c[i].d;
if (temp1 >= c[i].r){
temp = mid;
r = mid - 1;
}else {
l = mid + 1;
}
}
b[c[i].id] = temp;
}
rep1(i,1,n) cout << b[i] <<' ';
return 0;
}

【codeforces 589G】Hiring的更多相关文章

  1. 【codeforces 415D】Mashmokh and ACM(普通dp)

    [codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...

  2. 【codeforces 707E】Garlands

    [题目链接]:http://codeforces.com/contest/707/problem/E [题意] 给你一个n*m的方阵; 里面有k个联通块; 这k个联通块,每个连通块里面都是灯; 给你q ...

  3. 【codeforces 707C】Pythagorean Triples

    [题目链接]:http://codeforces.com/contest/707/problem/C [题意] 给你一个数字n; 问你这个数字是不是某个三角形的一条边; 如果是让你输出另外两条边的大小 ...

  4. 【codeforces 709D】Recover the String

    [题目链接]:http://codeforces.com/problemset/problem/709/D [题意] 给你一个序列; 给出01子列和10子列和00子列以及11子列的个数; 然后让你输出 ...

  5. 【codeforces 709B】Checkpoints

    [题目链接]:http://codeforces.com/contest/709/problem/B [题意] 让你从起点开始走过n-1个点(至少n-1个) 问你最少走多远; [题解] 肯定不多走啊; ...

  6. 【codeforces 709C】Letters Cyclic Shift

    [题目链接]:http://codeforces.com/contest/709/problem/C [题意] 让你改变一个字符串的子集(连续的一段); ->这一段的每个字符的字母都变成之前的一 ...

  7. 【Codeforces 429D】 Tricky Function

    [题目链接] http://codeforces.com/problemset/problem/429/D [算法] 令Si = A1 + A2 + ... + Ai(A的前缀和) 则g(i,j) = ...

  8. 【Codeforces 670C】 Cinema

    [题目链接] http://codeforces.com/contest/670/problem/C [算法] 离散化 [代码] #include<bits/stdc++.h> using ...

  9. 【codeforces 515D】Drazil and Tiles

    [题目链接]:http://codeforces.com/contest/515/problem/D [题意] 给你一个n*m的格子; 然后让你用1*2的长方形去填格子的空缺; 如果有填满的方案且方案 ...

随机推荐

  1. python之静态属性、类方法、静态方法

    静态属性.类方法.静态方法 1. 静态属性:在函数前加@property,将函数逻辑”封装“成数据属性,外部直接调用函数名,如同调用属性一样.这个函数是可以调用类和实例的属性的,    静态属性的作用 ...

  2. [USACO07OPEN]Catch That Cow

    题目:洛谷P1588.HDU2717 题目大意:有一个人在点$n$,一头牛在点$k$,人每秒能从$x$移动到点$x+1$.$x-1$.$2x$,牛不会动,求最少多少秒后人能移动到牛所在的$k$. 思路 ...

  3. Python 绘图与可视化 matplotlib 制作Gif动图

    参考链接:https://blog.csdn.net/theonegis/article/details/51037850 官方文档:https://matplotlib.org/3.1.0/api/ ...

  4. CRM系统 - 总结 (一) 权限

    1. 问:为什么程序需要权限控制? 答:生活中的权限限制,① 看灾难片电影<2012>中富人和权贵有权登上诺亚方舟,穷苦老百姓只有等着灾难的来临:② 屌丝们,有没有想过为什么那些长得漂亮身 ...

  5. ActiveMQ学习总结(4)——业界消息队列简介

    最近开发公司的短信平台,要用到消息队列,之前用的是亚马逊的SQS,考虑到后续业务发展,对消息推送的高并发要求,公司决定采用RabbitMQ来替换.借此机会开始熟悉各种MQ产品,下面先给大家简介下业界常 ...

  6. HDU 3073 Saving Beans

    Saving Beans Time Limit: 3000ms Memory Limit: 32768KB This problem will be judged on HDU. Original I ...

  7. NYIST 677 碟战

    碟战时间限制:2000 ms | 内存限制:65535 KB难度:4 描述知己知彼,百战不殆!在战争中如果被敌人掌握了自己的机密,失败是必然的.K国在一场战争中屡屡失败,就想到自己的某些城市可能会有敌 ...

  8. 在CentOS6.5下配置安装LVS

    先上一个图,在内网测试机上安装了一个虚拟机,已经安装好了CentOS 乖乖连wget都没有安装,先安装wget吧 sudo yum install wget

  9. Winserver服务器-AD字段对照简图

    AD字段对照简图

  10. 日志工具全面理解及配置应用---以Log4j例子

    一.日志系统基本常识 1.日志系统作用:将日志信息输出到控制台和文本文件,以追踪代码运行信息. 2.日志系统操作的是什么?日志系统打印信息,也是调用日志系统的log.Info(),log.Warn() ...