codeforces 589G G. Hiring(树状数组+二分)
题目链接:
G. Hiring
4 seconds
512 megabytes
standard input
standard output
The head of human resources department decided to hire a new employee. He created a test exercise for candidates which should be accomplished in at most m working days. Each candidate has to pass this test exercise. During the j-th day a candidate is allowed to be in the office for at most tj units of time.
Overall, n candidates decided to apply for the job and sent out their resumes. Based on data received the head has defined two parameters describing every candidate: di and ri. The parameter di is the time to get prepared for work which the i-th candidate spends each morning. This time doesn't depend on day. The parameter ri is the total working time needed for the i-th candidate to accomplish the whole test exercise.
Thus the time spent in the office in the j-th day consists of di units of time to get prepared and some units of time to proceed with the exercise. A candidate can skip entire working day and do not come to the office. Obviously in this case he doesn't spend di units of time to prepare.
To complete the exercise a candidate should spend exactly ri units of time working on the exercise (time to prepare is not counted here).
Find out for each candidate what is the earliest possible day when he can fully accomplish the test exercise. It is allowed to skip working days, but if candidate works during a day then he must spend di units of time to prepare for work before he starts progressing on the exercise.
The first line contains two integer numbers n, m (1 ≤ n, m ≤ 2·105) — the number of candidates and the maximum number of working days to do the test exercise.
The second line contains m integer numbers t1, t2, ..., tm (1 ≤ tj ≤ 106) — the durations of working days in time units.
The following n lines contain two integers each: di, ri (0 ≤ di ≤ 106, 1 ≤ ri ≤ 106) — how much time in the beginning of a day is required for i-th candidate before he starts his work on the test exercise and how much time it is needed for him to accomplish this task.
Output a sequence of n integer numbers b1, b2, ..., bn, where bi is the earliest day when the i-th candidate can finish the test exercise.
In case the i-th candidate cannot finish the test exercise in m days output bi = 0.
Days in this problem are numbered from 1 to m in the order they are given in the input.
3 3
4 2 5
1 3
2 5
3 4
1 3 0 题意:m天,每天允许的工作时间是t[i],n个工人,每个工人的工作总量需要时间为r[i],而且每天工作前要预热d[i]时间,问最早能在第几天完成工作;
思路:假设答案是ans,那么在前ans天中每天允许的时间大于d[i]的就是可以工作的一天t[i]-d[i]就是这天能完成的工作量,前ans天的加一块就>=r[i个工人],把这些按大到小排序,然后update到树状数组中,一个数组记录总量,一个记录有多少天update了sum-num*d[i]和r[i]比较就好了,这时又需要二分来快速找到答案ans;
AC代码:
#include <bits/stdc++.h>
using namespace std;
const int N=1e6+;
int n,m,a[N],ans[N],num[N],L,R;
long long sum[N];
struct nod
{
friend bool operator< (nod x,nod y)
{
return x.b>y.b;
}
int b,pos;
};
nod qu[N];
struct node
{
int l,r,pos;
};
node po[N];
bool cmp(node x,node y)
{
return x.l>y.l;
}
int lowbit(int x)
{
return x&(-x);
}
void update(int x,int nu)
{
while(x<=m)
{
num[x]++;
sum[x]+=(long long)nu;
x+=lowbit(x);
}
}
long long get_sum(int x)
{
long long s=;
while(x>)
{
s+=sum[x];
x-=lowbit(x);
}
return s;
}
long long get_num(int x)
{
long long s=;
while(x>)
{
s+=num[x];
x-=lowbit(x);
}
return s;
}
int get_ans(int x,int s)
{
long long fx=(long long)x;
int l=,r=m,mid;
while(l<=r)
{
mid=(l+r)>>;
if(get_sum(mid)-get_num(mid)*fx<s)l=mid+;
else r=mid-;
}
if(l>m)return ;
return l;
}
int main()
{
memset(num,,sizeof(num));
memset(sum,,sizeof(sum));
scanf("%d%d",&n,&m);
for(int i=;i<=m;i++)
{
scanf("%d",&a[i]);
qu[i].b=a[i];
qu[i].pos=i;
}
sort(qu+,qu+m+);
for(int i=;i<=n;i++)
{
scanf("%d%d",&L,&R);
po[i].l=L;
po[i].r=R;
po[i].pos=i;
}
sort(po+,po+n+,cmp);
int flag=;
for(int i=;i<=n;i++)
{
while(qu[flag].b>po[i].l&&flag<=m)
{
int y=qu[flag].pos;
update(y,a[y]);
flag++;
}
ans[po[i].pos]=get_ans(po[i].l,po[i].r);
}
for(int i=;i<=n;i++)
{
printf("%d ",ans[i]);
}
return ;
}
codeforces 589G G. Hiring(树状数组+二分)的更多相关文章
- [Codeforces 1208D]Restore Permutation (树状数组)
[Codeforces 1208D]Restore Permutation (树状数组) 题面 有一个长度为n的排列a.对于每个元素i,\(s_i\)表示\(\sum_{j=1,a_j<a_i} ...
- POJ 2828 Buy Tickets (线段树 or 树状数组+二分)
题目链接:http://poj.org/problem?id=2828 题意就是给你n个人,然后每个人按顺序插队,问你最终的顺序是怎么样的. 反过来做就很容易了,从最后一个人开始推,最后一个人位置很容 ...
- TZOJ 4602 高桥和低桥(二分或树状数组+二分)
描述 有个脑筋急转弯是这样的:有距离很近的一高一低两座桥,两次洪水之后高桥被淹了两次,低桥却只被淹了一次,为什么?答案是:因为低桥太低了,第一次洪水退去之后水位依然在低桥之上,所以不算“淹了两次”.举 ...
- POJ 2182 Lost Cows 【树状数组+二分】
题目链接:http://poj.org/problem?id=2182 Lost Cows Time Limit: 1000MS Memory Limit: 65536K Total Submis ...
- 树状数组+二分||线段树 HDOJ 5493 Queue
题目传送门 题意:已知每个人的独一无二的身高以及排在他前面或者后面比他高的人数,问身高字典序最小的排法 分析:首先对身高从矮到高排序,那么可以知道每个人有多少人的身高比他高,那么取较小值(k[i], ...
- P2161 [SHOI2009]会场预约[线段树/树状数组+二分/STL]
题目描述 PP大厦有一间空的礼堂,可以为企业或者单位提供会议场地.这些会议中的大多数都需要连续几天的时间(个别的可能只需要一天),不过场地只有一个,所以不同的会议的时间申请不能够冲突.也就是说,前一个 ...
- The Stream of Corning 2( 权值线段树/(树状数组+二分) )
题意: 有两种操作:1.在[l,r]上插入一条值为val的线段 2.问p位置上值第k小的线段的值(是否存在) 特别的,询问的时候l和p合起来是一个递增序列 1<=l,r<=1e9:1< ...
- 牛客多校第3场 J 思维+树状数组+二分
牛客多校第3场 J 思维+树状数组+二分 传送门:https://ac.nowcoder.com/acm/contest/883/J 题意: 给你q个询问,和一个队列容量f 询问有两种操作: 0.访问 ...
- Codeforces 567D - One-Dimensional Battle Ships - [树状数组+二分]
题目链接:https://codeforces.com/problemset/problem/567/D 题意: 在一个 $1 \times n$ 的网格上,初始摆放着 $k$ 只船,每只船的长度均为 ...
随机推荐
- 使用JMeter测试Java项目
一. Apache JMeter工具 1)简介 JMeter——一个100%的纯Java桌面应用,它是Apache组织的开放源代码项目,它是功能和性能测试的工具.JMeter可以用于测试静态或者动态资 ...
- ASP.NET动态网站制作(19)-- C#(2)
前言:C#的第二次课,依旧讲解C#的基础知识. 内容: 1.GC:垃圾回收机制,可以回收托管模块中的垃圾. 2.值类型和引用类型: (1)值类型:所有的数值类型都是值类型,如int,byte,sho ...
- unity shader 编辑器扩展类 ShaderGUI
这应该unity5才出的新功能了,今天看文档时刚巧看到了,就来尝试了一下. 效果如图: shader 的编辑器扩展分为2种方法: 是通过UnityEditor下的ShaderGUI类来实现的,形式比较 ...
- bugzilla部署记录
这两天部署了个bugzilla,记录如下. 1.主要参考文章 Bugzilla安装过程.Bugzilla使用手册及解决方案 如果你使用的系统是win7或者IIS是7.0的话,你可能还需要Win7 安装 ...
- share(发包方面)
share(发包方面) 接收所有map发过来的包,这个是GS线程驱动的 { for (;;) { //... if(!itMap.second->RecvData(Pkt)) break; if ...
- [精]poj2724
Purifying Machine Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 5027 Accepted: 1455 ...
- Wrapper配置详解及高级应用
将一个简单的程度如HelloWorld 的应用包装秤Wrapper 服务并不复杂,甚至可以认为非常简单.但是实际项目应用过程中我们的程序一般较庞大,运行环境也较复杂. 通过Wrapper 配置文件 ...
- linux c编程:进程环境
一 进程终止: ⼀个进程可以登记若⼲个(具体⾃⼰验证⼀下)个函数,这些函数由exit⾃动调⽤,这些函数被称为终⽌处理函数, atexit函数可以登记这些函数. exit调⽤终⽌处理函数的顺序和atex ...
- [转载]Java集合容器简介
Java集合容器主要有以下几类: 1,内置容器:数组 2,list容器:Vetor,Stack,ArrayList,LinkedList, CopyOnWriteArrayList(1.5),Attr ...
- JDBC【菜鸟学JAVA】
1:首先下载sqljdbc.jar,然后配置ClassPath,然后再在工程文件中把这个(sqljdbc.jar)架包引用上,就可以开始JAVA操作之旅了 打开Eclipse,“文件”→“新建”→“项 ...