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

本文归属: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. ACM-ICPC 2018 南京赛区网络预赛 E题

    ACM-ICPC 2018 南京赛区网络预赛 E题 题目链接: https://nanti.jisuanke.com/t/30994 Dlsj is competing in a contest wi ...

  2. 下载Android kernel

    方法一: https://source.android.com/setup/building-kernels 方法二: 在按照https://source.android.com/setup/down ...

  3. Docker容器内部端口映射到外部宿主机端口的方法小结

    转自:https://www.cnblogs.com/kevingrace/p/9453987.html Docker允许通过外部访问容器或者容器之间互联的方式来提供网络服务.容器启动之后,容器中可以 ...

  4. C# System.IO.StreamReader

    实现一个 TextReader,使其以一种特定的编码从字节流中读取字符. using System; using System.IO; class Test { public static void ...

  5. 安装rcssmin方法

    #安装rcssmin方法'''pip install wheelpip install rcssmin --install-option="--without-c-extensions&qu ...

  6. OpenLayers4地图实例-功能齐全

    网址:http://api.rivermap.cn/openlayers4/map.min.html 标注 工具

  7. 微信小程序官方DEMO解读

    我们在开始微信小程序开发的时候,对JS,HTML等前端知识一无所知,完完全全就是门外汉在尝试一个新的方向. 在下载好开发工具,微信就已经提供了一个DEMO例子: 从程序开发的角度来看这个陌生的目录结构 ...

  8. PHP,PSR开发规范

    https://github.com/hfcorriez/fig-standards/tree/zh_CN/%E6%8E%A5%E5%8F%97 PSR-1-basic-coding-standard ...

  9. lsb_release command not found

    Linux里的lsb_release命令用来查看当前系统的发行版信 息(prints certain LSB (Linux Standard Base) and Distribution inform ...

  10. 【原创 深度学习与TensorFlow 动手实践系列 - 3】第三课:卷积神经网络 - 基础篇

    [原创 深度学习与TensorFlow 动手实践系列 - 3]第三课:卷积神经网络 - 基础篇 提纲: 1. 链式反向梯度传到 2. 卷积神经网络 - 卷积层 3. 卷积神经网络 - 功能层 4. 实 ...