Codeforces 609F Frogs and mosquitoes 线段树
用线段树维护每个点覆盖的最小id, 用multiset维护没有吃的蚊子。
#include<bits/stdc++.h>
#define LL long long
#define fi first
#define se second
#define mk make_pair
#define PLL pair<LL, LL>
#define PLI pair<LL, int>
#define PII pair<int, int>
#define SZ(x) ((int)x.size())
#define ull unsigned long long using namespace std; const int N = 2e5 + ;
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const int mod = ;
const double eps = 1e-;
const double PI = acos(-); struct Forg {
int x, cnt, id;
LL t;
bool operator < (const Forg& rhs) const {
return x < rhs.x;
}
void print() {
printf("id: %d x: %d cnt: %d t: %lld\n", id, x, cnt, t);
}
}; int n, m;
Forg frog[N];
PII mos[N]; LL anst[N], ansc[N]; vector<LL> oo;
multiset<PII> uneat; int getPosL(LL x) {
return lower_bound(oo.begin(), oo.end(), x) - oo.begin() + ;
}
int getPosR(LL x) {
return upper_bound(oo.begin(), oo.end(), x) - oo.begin();
} namespace SGT {
#define lson l, mid, rt << 1
#define rson mid + 1, r, rt << 1 | 1
int a[N << ];
void init() {
memset(a, inf, sizeof(a));
}
void update(int L, int R, int val, int l, int r, int rt) {
if(L > R) return;
if(l >= L && r <= R) {
a[rt] = min(a[rt], val);
return;
}
int mid = l + r >> ;
if(L <= mid) update(L, R, val, lson);
if(R > mid) update(L, R, val, rson);
}
int query(int p, int l, int r, int rt) {
if(l == r) return a[rt];
int mid = l + r >> ;
if(p <= mid) return min(a[rt], query(p, lson));
else return min(a[rt], query(p, rson));
}
} int main() {
scanf("%d%d", &n, &m);
for(int i = ; i <= n; i++) {
scanf("%d%lld", &frog[i].x, &frog[i].t);
frog[i].id = i;
}
sort(frog + , frog + + n);
for(int i = ; i <= m; i++) {
scanf("%d%d", &mos[i].fi, &mos[i].se);
oo.push_back(mos[i].fi);
}
sort(oo.begin(), oo.end());
oo.erase(unique(oo.begin(), oo.end()), oo.end());
SGT::init();
for(int i = ; i <= n; i++) {
SGT::update(getPosL(frog[i].x), getPosR(frog[i].x + frog[i].t), i, , SZ(oo), );
}
for(int i = ; i <= m; i++) {
int p = mos[i].fi, b = mos[i].se;
int who = SGT::query(getPosL(p), , SZ(oo), );
if(who < inf) {
LL pre = frog[who].x + frog[who].t;
frog[who].t += b;
frog[who].cnt++;
LL now = frog[who].x + frog[who].t;
SGT::update(getPosL(pre + ), getPosR(now), who, , SZ(oo), );
while(SZ(uneat)) {
auto it = uneat.lower_bound(mk(pre + , -inf));
if(it == uneat.end()) break;
who = SGT::query(getPosL(it->fi), , SZ(oo), );
if(who >= inf) break;
frog[who].t += it->se;
frog[who].cnt++;
now = frog[who].x + frog[who].t;
SGT::update(getPosL(pre + ), getPosR(now), who, , SZ(oo), );
uneat.erase(it);
}
} else {
uneat.insert(mos[i]);
}
}
for(int i = ; i <= n; i++)
anst[frog[i].id] = frog[i].t, ansc[frog[i].id] = frog[i].cnt;
for(int i = ; i <= n; i++) printf("%lld %lld\n", ansc[i], anst[i]);
return ;
} /*
*/
Codeforces 609F Frogs and mosquitoes 线段树的更多相关文章
- [Educational Round 3][Codeforces 609F. Frogs and mosquitoes]
这题拖了快一周_(:з」∠)_就把这货单独拿出来溜溜吧~ 本文归属:Educational Codeforces Round 3 题目链接: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 Good bye 2016 E 线段树维护dp区间合并
codeforces Good bye 2016 E 线段树维护dp区间合并 题目大意:给你一个字符串,范围为‘0’~'9',定义一个ugly的串,即串中的子串不能有2016,但是一定要有2017,问 ...
- codeforces 22E XOR on Segment 线段树
题目链接: http://codeforces.com/problemset/problem/242/E E. XOR on Segment time limit per test 4 seconds ...
- Codeforces 588E. A Simple Task (线段树+计数排序思想)
题目链接:http://codeforces.com/contest/558/problem/E 题意:有一串字符串,有两个操作:1操作是将l到r的字符串升序排序,0操作是降序排序. 题解:建立26棵 ...
- Codeforces Gym 100803G Flipping Parentheses 线段树+二分
Flipping Parentheses 题目连接: http://codeforces.com/gym/100803/attachments Description A string consist ...
- Codeforces GYM 100114 D. Selection 线段树维护DP
D. Selection Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100114 Descriptio ...
- Codeforces 444C DZY Loves Colors(线段树)
题目大意:Codeforces 444C DZY Loves Colors 题目大意:两种操作,1是改动区间上l到r上面德值为x,2是询问l到r区间总的改动值. 解题思路:线段树模板题. #inclu ...
- Codeforces 85D Sum of Medians(线段树)
题目链接:Codeforces 85D - Sum of Medians 题目大意:N个操作,add x:向集合中加入x:del x:删除集合中的x:sum:将集合排序后,将集合中全部下标i % 5 ...
随机推荐
- Appium+Java(三)搭建环境之踩过的坑
一.原因 有最少两年多没写手机自动化测试了,正巧公司有需求搞TOC端自动化测试调研,先入为主,因为之前写过appium所以先用它埋点试水了 二.现象: 1.我早期的appium版本是v1.4.16 2 ...
- django配置发送邮箱
该邮箱配置后台发送邮箱验证使用 settings内配置 # 服务器地址 EMAIL_HOST = 'smtp.163.com' # 端口,邮箱默认动态端口 25 EMAIL_PORT = 25 # 邮 ...
- oracle 新增一条数据时设置id自增
CREATE SEQUENCE test_seq --创建一个test_seq序列INCREMENT BY 1 --每次加1START WITH 1 --从1开始NOMAXVALUE ...
- 《Spring5官方文档》新功能(4,3)
<Spring5官方文档>新功能 原文链接 译者:supriseli Spring框架的新功能 这一章主要提供Spring框架新的功能和变更. 升级到新版本的框架可以参考.Spring g ...
- 面向对象(metaclass继承高级用法)
方法一:# class MyType(type):# def __init__(self,*args,**kwargs):# print('132')# super(MyType,self).__in ...
- python-并发编程之多进程
一.操作系统基础: 进程的概念起源于操作系统,操作系统其它所有概念都是围绕进程来的,所以我们了解进程之前先来了解一下操作系统 操作系统位于计算机硬件与应用软件之间,本质也是一个软件.操作系统由操作系统 ...
- 本文转自 MyEclipse 2015反编译插件安装
本文转自MyEclipse 2015反编译插件安装 分享一下下载插件的地址,百度网盘:链接:http://pan.baidu.com/s/1nturiAH 密码:yk73 其次:我来说下具体操作步骤: ...
- Confluence 6 虚拟文件和文件夹
在取消点赞事件中,你可能会遇到 WebDAV 客户端的问题或者不稳定的情况,你可以启用访问自动创建(虚拟)文件和文件夹. 备注: 在默认情况下,这个选项隐藏在 'WebDAV Configurati ...
- Confluence 6 为发送邮件配置服务器
配置你的 Confluence 服务器发送电子邮件消息能够允许你的 Confluence 用户: 接受邮件通知和每天更新报表. 通过电子邮件发送一个页面. 你可以通过配置 'From' 字段中的内容来 ...
- Confluence 6 整合到支持的附件存储选项
如果你现在正在存储附件到 WebDav 或者你的数据库中.你可以整合附件的存储到文件系统中.当你的附件从数据库中被合并到文件系统后,你存储在数据库中的附件数据就可以从数据库中删除了. 当附件合并进行的 ...