这题拖了快一周_(:з」∠)_就把这货单独拿出来溜溜吧~

本文归属:Educational Codeforces Round 3

题目链接:609F - Frogs and mosquitoes

题目大意:在\(x\)轴上有\(n\)只青蛙,每只青蛙有对应的位置\(x_i\)和他舌头的长度\(t_i\),青蛙可以吃到位置在\([x_i,t_i]\)内的蚊子。\(m\)只蚊子依次降落在位置\(p_i\)上,如果这只蚊子在某只青蛙的攻击范围内,那么他会被这只青蛙吃掉,若有多只青蛙可以吃掉这只蚊子,处在最左边位置的青蛙会吃掉他,吃掉这只蚊子的青蛙舌头长度会增长\(b_i\)。若舌头增长后可以吃掉尚还存活的蚊子,则这只青蛙会继续吃他能吃到的所有蚊子。问最后每只青蛙能吃到的蚊子数目\(c_i\)和最终的舌头长度\(l_i\)。

题解:考虑用树状数组维护坐标小于\(x\)的青蛙最远能吃到哪,由于\(x_i\)的范围较大所以需要离散化处理,之后就是树状数组求区间最大值的问题。开一个\(pair<int,int>a[N]\),记录位置第\(i\)小的青蛙对应的位置及其标号,那么每次进来一只蚊子可以用lowerbound/upperbound来确定最后一只在\(p_i\)左边的青蛙,之后再进行二分查找,找出能吃到这只蚊子的青蛙并模拟吃蚊子的过程即可。注意一下对暂时不会被吃掉的蚊子的特判。

#include<bits/stdc++.h>
using namespace std;
#define N 200001
#define LL long long
#define mp make_pair
pair<LL,LL>a[N];
set<pair<LL,LL> >mos;
LL n,m,x[N],t[N],p,b[N],f[N],c[N];
LL lowbit(LL x){return x&(-x);}
void change(LL x,LL c){while(x<N)f[x]=max(f[x],c),x+=lowbit(x);}
LL ask(LL x){LL res=;while(x>)res=max(res,f[x]),x-=lowbit(x);return res;}
int main()
{
scanf("%I64d%I64d",&n,&m);
for(LL i=;i<=n;i++)
scanf("%I64d%I64d",&x[i],&t[i]),a[i]=mp(x[i],i);
sort(a+,a+n+);
for(LL i=;i<=n;i++)change(i,x[a[i].second]+t[a[i].second]);
for(LL i=;i<=m;i++)
{
scanf("%I64d%I64d",&p,&b[i]);
LL l=,r=upper_bound(a+,a+n+,mp(p,n))-a-;
if(p<a[].first)continue;
if(p>ask(r)){mos.insert(mp(p,i));continue;}
while(l<r)
{
LL mid=l+r>>;
if(ask(mid)>=p)r=mid;
else l=mid+;
}
if(a[l].first>p){mos.insert(mp(p,i));continue;}
LL id=a[l].second;
t[id]+=b[i],change(l,x[id]+t[id]),c[id]++;
for(auto it=mos.lower_bound(mp(x[id],));it!=mos.end() && (*it).first<=x[id]+t[id];)
t[id]+=b[(*it).second],change(l,x[id]+t[id]),c[id]++,mos.erase(it++);
}
for(LL i=;i<=n;i++)
printf("%I64d %I64d\n",c[i],t[i]);
return ;
}

[Educational Round 3][Codeforces 609F. Frogs and mosquitoes]的更多相关文章

  1. codeforces 609F. Frogs and mosquitoes 二分+线段树

    题目链接 F. Frogs and mosquitoes time limit per test 2 seconds memory limit per test 512 megabytes input ...

  2. Codeforces 609F Frogs and mosquitoes 线段树

    Frogs and mosquitoes 用线段树维护每个点覆盖的最小id, 用multiset维护没有吃的蚊子. #include<bits/stdc++.h> #define LL l ...

  3. [Educational Round 5][Codeforces 616F. Expensive Strings]

    这题调得我心疲力竭...Educational Round 5就过一段时间再发了_(:з」∠)_ 先后找了三份AC代码对拍,结果有两份都会在某些数据上出点问题...这场的数据有点水啊_(:з」∠)_[ ...

  4. [Educational Round 3][Codeforces 609E. Minimum spanning tree for each edge]

    这题本来是想放在educational round 3的题解里的,但觉得很有意思就单独拿出来写了 题目链接:609E - Minimum spanning tree for each edge 题目大 ...

  5. [Educational Round 17][Codeforces 762F. Tree nesting]

    题目连接:678F - Lena and Queries 题目大意:给出两个树\(S,T\),问\(S\)中有多少连通子图与\(T\)同构.\(|S|\leq 1000,|T|\leq 12\) 题解 ...

  6. [Educational Round 13][Codeforces 678F. Lena and Queries]

    题目连接:678F - Lena and Queries 题目大意:要求对一个点集实现二维点对的插入,删除,以及询问\(q\):求\(max(x\cdot q+y)\) 题解:对每个点集内的点\(P( ...

  7. [Educational Round 10][Codeforces 652F. Ants on a Circle]

    题目连接:652F - Ants on a Circle 题目大意:\(n\)个蚂蚁在一个大小为\(m\)的圆上,每个蚂蚁有他的初始位置及初始面向,每个单位时间蚂蚁会朝着当前面向移动一个单位长度,在遇 ...

  8. [Educational Round 59][Codeforces 1107G. Vasya and Maximum Profit]

    咸鱼了好久...出来冒个泡_(:з」∠)_ 题目连接:1107G - Vasya and Maximum Profit 题目大意:给出\(n,a\)以及长度为\(n\)的数组\(c_i\)和长度为\( ...

  9. CF# Educational Codeforces Round 3 F. Frogs and mosquitoes

    F. Frogs and mosquitoes time limit per test 2 seconds memory limit per test 512 megabytes input stan ...

随机推荐

  1. sql server ExecuteNonQuery()返回受影响行数不适用select语句

    SqlCommand.ExecuteNonQuery 方法对连接执行 Transact-SQL 语句并返回受影响的行数. 对于 UPDATE.INSERT 和 DELETE 语句,返回值为该命令所影响 ...

  2. Git远程仓库地址变更本地如何修改

    以项目test为例: 老地址:http://192.168.1.1:9797/john/test.git 新地址:http://git.xxx.xxx/john/test.git 远程仓库名称: or ...

  3. 使用python实现深度神经网络 3(转)

    使用python实现深度神经网络 3 快速计算梯度的魔法--反向传播算法 快速计算梯度的魔法--反向传播算法 一.实验介绍 1.1 实验内容 第一次实验最后我们说了,我们已经学习了深度学习中的模型mo ...

  4. 修改Electron的libcc(libchromiumcontent)源码,重新编译electron, 设置event.isTrusted为true

    VPN非常注意: 编译的过程需要使用VPN, 否者chromium的源代码无法下载, 后面会出现总总问题 Electron的编译环境, 推荐使用物理机: win10 64位 英文版, 为了避免后期出现 ...

  5. PL/SQL学习笔记之日期时间

    一:PL/SQL时间相关类型 PL/SQL提供两个和日期时间相关的数据类型: 日期时间(Datetime)数据类型 时间间隔类型 二:日期时间类型 datetime数据类型有: DATE TIMEST ...

  6. java AOP Before, After, AfterReturning, AfterThrowing, or Around 注解

    https://www.eclipse.org/aspectj/doc/next/adk15notebook/ataspectj-pcadvice.html Advice In this sectio ...

  7. std::nothrow 的使用心得

    std::nothrow 意思是说,不要跑出异常,改为返回一个nullptr. 一般的使用场景是,建议new的时候使用,避免使用try-catch来捕捉异常. 比如: float m_words = ...

  8. 51单片机stack堆栈

    一般编译器的堆栈用于保存局部变量.函数的参数.函数的返回值.中断上下文信息等.但Keil对局部变量.函数参数预先分配空间(放在静态全局变量区),Keil的堆栈只是用于保存函数嵌套调用的PC.中断上下文 ...

  9. mysql 动态增加列,查找表中有多少列,具体什么列。 通过JSON生成mysql表 支持子JSON

    好消息, 程序员专用早餐机.和掌柜说 ideaam,可以节省20元. 点击链接  或復·制这段描述¥k3MbbVKccMU¥后到淘♂寳♀ 或者 淘宝扫码 支持下同行哈 ---------------- ...

  10. 转:slf4j-api、slf4j-log4j12、log4j之间关系

    原文:https://www.cnblogs.com/lujiango/p/8573411.html 1. slf4j-api slf4j:Simple Logging Facade for Java ...