[Educational Round 3][Codeforces 609F. Frogs and mosquitoes]
这题拖了快一周_(:з」∠)_就把这货单独拿出来溜溜吧~
本文归属: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]的更多相关文章
- codeforces 609F. Frogs and mosquitoes 二分+线段树
题目链接 F. Frogs and mosquitoes time limit per test 2 seconds memory limit per test 512 megabytes input ...
- Codeforces 609F Frogs and mosquitoes 线段树
Frogs and mosquitoes 用线段树维护每个点覆盖的最小id, 用multiset维护没有吃的蚊子. #include<bits/stdc++.h> #define LL l ...
- [Educational Round 5][Codeforces 616F. Expensive Strings]
这题调得我心疲力竭...Educational Round 5就过一段时间再发了_(:з」∠)_ 先后找了三份AC代码对拍,结果有两份都会在某些数据上出点问题...这场的数据有点水啊_(:з」∠)_[ ...
- [Educational Round 3][Codeforces 609E. Minimum spanning tree for each edge]
这题本来是想放在educational round 3的题解里的,但觉得很有意思就单独拿出来写了 题目链接:609E - Minimum spanning tree for each edge 题目大 ...
- [Educational Round 17][Codeforces 762F. Tree nesting]
题目连接:678F - Lena and Queries 题目大意:给出两个树\(S,T\),问\(S\)中有多少连通子图与\(T\)同构.\(|S|\leq 1000,|T|\leq 12\) 题解 ...
- [Educational Round 13][Codeforces 678F. Lena and Queries]
题目连接:678F - Lena and Queries 题目大意:要求对一个点集实现二维点对的插入,删除,以及询问\(q\):求\(max(x\cdot q+y)\) 题解:对每个点集内的点\(P( ...
- [Educational Round 10][Codeforces 652F. Ants on a Circle]
题目连接:652F - Ants on a Circle 题目大意:\(n\)个蚂蚁在一个大小为\(m\)的圆上,每个蚂蚁有他的初始位置及初始面向,每个单位时间蚂蚁会朝着当前面向移动一个单位长度,在遇 ...
- [Educational Round 59][Codeforces 1107G. Vasya and Maximum Profit]
咸鱼了好久...出来冒个泡_(:з」∠)_ 题目连接:1107G - Vasya and Maximum Profit 题目大意:给出\(n,a\)以及长度为\(n\)的数组\(c_i\)和长度为\( ...
- 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 ...
随机推荐
- MySql的优化步骤
MySql优化的一般步骤: 1.通过show status 命令了解各种sql的执行效率 SHOW STATUS提供msyql服务器的状态信息 一般情况下,我们只需要了解以”Com”开头的指令 sho ...
- 咏南DELPHI7中间件+开发框架
咏南DELPHI7中间件+开发框架 演示下载:链接: https://pan.baidu.com/s/1bulGBIZ6A1nkeErxIrGsGA 密码: 22dk 解压后运行ynmain.exe ...
- 用distinct or array_unique
在 Mysql 获取数据时,如果想获取某一列去重数据,如果获取呢 举个例子: advert_pro_ad 表 CREATE TABLE `advert_pro_ad` ( `advert_id` ) ...
- C++ 中的不定参数与格式化字符串 # ## vsprintf
日志打印或者格式字符串时,可能会用到不定参数的使用,这里记录一下. 格式化字符串有很多方法: snprintf std::stringstream # ##的使用 ##是一个连接符号,用于把参数连在一 ...
- 大疆无人机M100相关问题解决过程
1.遥控器升级问题 iOS端使用app升级,重复尝试了5次+,还是无法升级.卸载app重新安装,依旧是无法升级.使用Android app升级,一次搞定. 2.飞行器固件升级(云台别选错了) http ...
- git主要操作命令
1.创建版本库 (1)初始化一个 Git仓库,使用git init命令 (在相应的本地库目录下执行,将该目录初始化为一个Git库): (2)添加文件到Git仓库,分两步: 第一步,使用命令 git a ...
- Ant之build.xml配置详解【转】
原文:https://blog.csdn.net/mevicky/article/details/72828554 前言国内关于build.xml的配置资料太零散了,实在是受不了,故而将自己的笔记整理 ...
- NodeJs之fs
NodeJs版本:4.4.4 fs的实用方法 查看文件信息(fs.stat) 定义:fs.stat(path, callback) var fs = require('fs'); fs.stat('t ...
- maven 使用 国内镜像的方法 解决依赖下载慢
转自:http://blog.csdn.net/banqgg/article/details/55804569 Maven是当前流行的项目管理工具,但官方的库在国外经常连不上,连上也下载速度很慢.国内 ...
- ero-configuration Web Application Debugging with Xdebug and PhpStorm
1. Install Xdebug To use Xdebug with PhpStorm for debugging PHP applications, you need to have a PHP ...