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

本文归属: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. Delphi 获取当前鼠标下的控件内容

    Delphi 获取当前鼠标下的控件内容 主要函数: GetCursorPos://获取鼠标的位置 WindowFromPoint://获取制定point下的handle GetClassName:// ...

  2. Linux软件开发常用的软件包(持续更新中)

    下面是Linux开发常用的软件包: 软件包的名称 作用描述 安装方式 build-essential   sudo apt-get install build-essential policycore ...

  3. 在Mac平台上安装配置ELK时的一些总结

    一.前言 大数据处理是流行的一些表现,在不断壮大的数据处理中,怎么样处理数据才是我们继续做好开发的正道.本文章来自网络,不敢原创,但是也有很大借鉴.   二.MAC安装ELK   首先是安装elast ...

  4. [原创]Delphi XE10 dxLayoutControl 控件应用指南

    DevExpress VCL套件是一套非常强大的界面控件,可惜关于Delphi开发方面的说明太少,有些控件使用起来一头雾水,不知从何下手.本节详细介绍在Delphi Xe10 Seattle中如何利用 ...

  5. Git - 生成ssh key步骤以及如何clone所有的远程分支

    https://www.cnblogs.com/gongyuhonglou/p/6922721.html 2. 生成ssh key $ ssh-keygen -t rsa -C “邮箱”按3个回车,密 ...

  6. Love2D游戏引擎制作贪吃蛇游戏

    代码地址如下:http://www.demodashi.com/demo/15051.html Love2D游戏引擎制作贪吃蛇游戏 内附有linux下的makefile,windows下的生成方法请查 ...

  7. Navicat Premium 12破解方法

    来源网址:https://www.jianshu.com/p/42a33b0dda9c 1.按步骤安装Navicat Premium,如果没有可以去官网下载:http://www.navicat.co ...

  8. ASP.NET MVC Web API 学习笔记---Web API概述及程序示例

    1. Web API简单说明 近来很多大型的平台都公开了Web API.比如百度地图 Web API,做过地图相关的人都熟悉.公开服务这种方式可以使它易于与各种各样的设备和客户端平台集成功能,以及通过 ...

  9. centos7环境安装ElasticSearch

    操作系统: Centos7 .64位 ========================================= 查看系统版本和系统位数: [root@localhost /]# cat /e ...

  10. MOD(motion Object Detection)介绍

    Motion Detection or Moving Object Detection 称之为运动侦测,移动侦测,移动检测 MOD全称为Moving Object Detection,中文“移动物体检 ...