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

本文归属: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. Android的Databinding-资源绑定

    databinding还能对布局的资源文件进行绑定. <data class="ResourceBinding"> <variable name="la ...

  2. go依赖包下载加速方法及github加速

    go依赖包下载加速方法及github加速 对于https://github.com/kubernetes/kubernetes整个仓库大小为近900M,下载起来那个伤心: 方法一:使用码云 这是码云上 ...

  3. 什么是ip代理

    1.什么是代理IP(代理服务器),代理IP(代理服务器)有什么用? 代理服务器英文全称是(Proxy Server),也叫做代理IP,其功能就是代理网络用户去取得网络信息.形象的说:它是网络信息的中转 ...

  4. Execution failed for task ':compileDebugAidl'.

    昨天终于升级了下Ubuntu系统到16.04LTS,之前是12.04LTS(导致内网一些同事开发的网址无法打开,以及其他工具软件无法安装). 安装完android开发工具,运行之前的project,出 ...

  5. Linear SVM和LR的区别和联系

    首先,SVM和LR(Logistic Regression)都是分类算法.SVM通常有4个核函数,其中一个是线性核,当使用线性核时,SVM就是Linear SVM,其实就是一个线性分类器,而LR也是一 ...

  6. oralce 11.2.0.4手动创建EM

    安装完oracle,启动dbconsole,失败 [oracle@elearning admin]$ emctl start dbconsole OC4J Configuration issue. / ...

  7. java 获取当天(今日)零点零分零秒

    两种方法 一种得到的是时间戳,一种得到是日期格式: 1.日期格式的 Calendar calendar = Calendar.getInstance(); calendar.setTime(new D ...

  8. ios the request was denied by service delegate for reason unspecified

    报错的情况如下: xcode8(The request was denied by service delegate (SBMainWorkspace) for reason: Unspecified ...

  9. SublimeText3追踪函数工具CTags设置及使用

    第一步:在 ST3 安装 CTags 插件 1. 在 ST3 快捷键 Crtl+Shift+P 然后输入 pci ,选择“ Package Control: Install Package ”启动安装 ...

  10. 关于java中死锁的总结

    关于死锁,估计很多程序员都碰到过,并且有时候这种情况出现之后的问题也不是非常好排查,下面整理的就是自己对死锁的认识,以及通过一个简单的例子来来接死锁的发生,自己是做python开发的,但是对于死锁的理 ...