P1083
题意就是n天 每天有r[i]个教室可用 问你有m个申请 必须按顺序来 从Q[i].l 到 Q[i].r 要用Q[i].d个教室
如果都能满足 输出0 如果有按顺序哪个不能满足输出不能满足
我们首先发现答案继续单调性 那么可以二分
二分的时候check数组如何满足检验呢?
其实就是差分数组加一下 前缀和求每天的实际使用教室值和最大教室判断一下check即可
check函数为此
bool check(int mid)
{
memset(b,0,sizeof(b));
ll tmp = 0;
for(int i = 1;i<=mid;++i)
b[Q[i].l]+=Q[i].d,b[Q[i].r+1]-=Q[i].d;
sum[0] = 0;
for(int i = 1;i<=n;i++)
{
sum[i] = sum[i-1]+b[i];
if(sum[i]>a[i]) return false;
}
return true;
}
代码如下
/*
if you can't see the repay
Why not just work step by step
rubbish is relaxed
to ljq
*/
#include <cstdio>
#include <cstring>
#