codeforces 609F. Frogs and mosquitoes 二分+线段树
2 seconds
512 megabytes
standard input
standard output
There are n frogs sitting on the coordinate axis Ox. For each frog two values xi, ti are known — the position and the initial length of the tongue of the i-th frog (it is guaranteed that all positions xi are different). m mosquitoes one by one are landing to the coordinate axis. For each mosquito two values are known pj — the coordinate of the position where the j-th mosquito lands and bj — the size of the j-th mosquito. Frogs and mosquitoes are represented as points on the coordinate axis.
The frog can eat mosquito if mosquito is in the same position with the frog or to the right, and the distance between them is not greater than the length of the tongue of the frog.
If at some moment several frogs can eat a mosquito the leftmost frog will eat it (with minimal xi). After eating a mosquito the length of the tongue of a frog increases with the value of the size of eaten mosquito. It's possible that after it the frog will be able to eat some other mosquitoes (the frog should eat them in this case).
For each frog print two values — the number of eaten mosquitoes and the length of the tongue after landing all mosquitoes and after eating all possible mosquitoes by frogs.
Each mosquito is landing to the coordinate axis only after frogs eat all possible mosquitoes landed before. Mosquitoes are given in order of their landing to the coordinate axis.
First line contains two integers n, m (1 ≤ n, m ≤ 2·105) — the number of frogs and mosquitoes.
Each of the next n lines contains two integers xi, ti (0 ≤ xi, ti ≤ 109) — the position and the initial length of the tongue of the i-th frog. It is guaranteed that all xi are different.
Next m lines contain two integers each pj, bj (0 ≤ pj, bj ≤ 109) — the position and the size of the j-th mosquito.
Print n lines. The i-th line should contain two integer values ci, li — the number of mosquitoes eaten by the i-th frog and the length of the tongue of the i-th frog.
4 6
10 2
15 0
6 1
0 1
110 10
1 1
6 0
15 10
14 100
12 2
3 114
1 10
1 1
1 2
1 2
10 2
20 2
12 1
1 3 题意: 给出n只青蛙, 每个青蛙两个属性, 坐标x, 以及舌头的长度t。 在给出m个蚊子, 每个蚊子两个属性, 坐标x以及值val。 青蛙只能吃和它在同一个点的蚊子和在他右边并且它舌头够得到的蚊子。 如果一个蚊子可以被多只青蛙吃, 那么它被最左边的吃。 青蛙吃掉一个蚊子后, 舌头会变长, 变长的值为val。 蚊子的顺序按照蚊子降落的顺序给出。
#include <iostream>
#include <vector>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <queue>
#include <stack>
#include <bitset>
using namespace std;
#define pb(x) push_back(x)
#define ll long long
#define mk(x, y) make_pair(x, y)
#define lson l, m, rt<<1
#define mem(a) memset(a, 0, sizeof(a))
#define rson m+1, r, rt<<1|1
#define mem1(a) memset(a, -1, sizeof(a))
#define mem2(a) memset(a, 0x3f, sizeof(a))
#define rep(i, n, a) for(int i = a; i<n; i++)
#define fi first
#define se second
typedef pair<int, int> pll;
const double PI = acos(-1.0);
const double eps = 1e-;
const int mod = 1e9+;
const int inf = ;
const int dir[][] = { {-, }, {, }, {, -}, {, } };
const int maxn = 2e5+;
ll maxx[maxn<<];
void pushUp(int rt) {
maxx[rt] = max(maxx[rt<<], maxx[rt<<|]);
}
void update(int p, int val, int l, int r, int rt) {
if(l == r) {
maxx[rt] += val;
return ;
}
int m = l+r>>;
if(p<=m)
update(p, val, lson);
else
update(p, val, rson);
pushUp(rt);
}
ll query(int L, int R, int l, int r, int rt) {
if(L<=l&&R>=r) {
return maxx[rt];
}
int m = l+r>>;
ll ret = ;
if(L<=m)
ret = max(ret, query(L, R, lson));
if(R>m)
ret = max(ret, query(L, R, rson));
return ret;
}
pair<int, ll> frog[maxn];
ll tog[maxn];
int id[maxn], sum[maxn], a[maxn], n, b[maxn];
multiset <pll> mp;
int check(int num) {
int pos = upper_bound(a+, a+n+, num)-a;
if(pos == || query(, pos-, , n, )<num)
return -;
int l = , r = pos-, tmp = ;
while(l <= r) {
int mid = l+r>>;
if(query(, mid, , n, )>=num) {
r = mid-;
tmp = mid;
} else {
l = mid+;
}
}
return tmp;
}
int main() {
int m;
cin>>n>>m;
for(int i = ; i<=n; i++) {
scanf("%d%d", &frog[i].fi, &frog[i].se);
a[i] = frog[i].fi;
}
sort(a+, a+n+);
for(int i = ; i<=n; i++) {
int pos = lower_bound(a+, a+n+, frog[i].fi)-a;
b[i] = pos;
id[pos] = i;
update(pos, frog[i].fi+frog[i].se, , n, );
}
while(m--) {
int x, y;
scanf("%d%d", &x, &y);
int pos = check(x);
if(pos == -) {
mp.insert(mk(x, y));
} else {
tog[pos] += y;
sum[pos]++;
update(pos, y, , n, );
while(!mp.empty()) {
auto it = mp.lower_bound(mk(frog[id[pos]].first, ));
if(it == mp.end() || it->first>frog[id[pos]].second+tog[pos]+frog[id[pos]].first)
break;
sum[pos]++;
tog[pos] += it->second;
update(pos, it->second, , n, );
mp.erase(it);
}
}
}
for(int i = ; i<=n; i++) {
printf("%d %I64d\n", sum[b[i]], tog[b[i]]+frog[i].second);
}
}
codeforces 609F. Frogs and mosquitoes 二分+线段树的更多相关文章
- Codeforces 609F Frogs and mosquitoes 线段树
Frogs and mosquitoes 用线段树维护每个点覆盖的最小id, 用multiset维护没有吃的蚊子. #include<bits/stdc++.h> #define LL l ...
- [Educational Round 3][Codeforces 609F. Frogs and mosquitoes]
这题拖了快一周_(:з」∠)_就把这货单独拿出来溜溜吧~ 本文归属:Educational Codeforces Round 3 题目链接:609F - Frogs and mosquitoes 题目 ...
- Codeforces 889F Letters Removing(二分 + 线段树 || 树状数组)
Letters Removing 题意:给你一个长度为n的字符串,然后进行m次删除操作,每次删除区间[l,r]内的某个字符,删除后并且将字符串往前补位,求删除完之后的字符串. 题解:先开80个set ...
- Educational Codeforces Round 61 D 二分 + 线段树
https://codeforces.com/contest/1132/problem/D 二分 + 线段树(弃用结构体型线段树) 题意 有n台电脑,只有一个充电器,每台电脑一开始有a[i]电量,每秒 ...
- HDU4614 Vases and Flowers 二分+线段树
分析:感觉一看就是二分+线段树,没啥好想的,唯一注意,当开始摆花时,注意和最多能放的比大小 #include<iostream> #include<cmath> #includ ...
- J - Joseph and Tests Gym - 102020J (二分+线段树)
题目链接:https://cn.vjudge.net/contest/283920#problem/J 题目大意:首先给你n个门的高度,然后q次询问,每一次询问包括两种操作,第一种操作是将当前的门的高 ...
- 【BZOJ-3110】K大数查询 整体二分 + 线段树
3110: [Zjoi2013]K大数查询 Time Limit: 20 Sec Memory Limit: 512 MBSubmit: 6265 Solved: 2060[Submit][Sta ...
- hdu6070 Dirt Ratio 二分+线段树
/** 题目:hdu6070 Dirt Ratio 链接:http://acm.hdu.edu.cn/showproblem.php?pid=6070 题意:给定n个数,求1.0*x/y最小是多少.x ...
- [Codeforces 266E]More Queries to Array...(线段树+二项式定理)
[Codeforces 266E]More Queries to Array...(线段树+二项式定理) 题面 维护一个长度为\(n\)的序列\(a\),\(m\)个操作 区间赋值为\(x\) 查询\ ...
随机推荐
- VBA 开发学习--基础语法3
VBA字符串函数列表 Trim(string) 去掉string左右两端空白 Ltrim(string) 去掉string左端空白 Rtrim(string) 去掉string右端空白 Len(str ...
- md笔记——使用 @font-face 引入你喜欢的字体
使用 @font-face 引入你喜欢的字体 原理 CSS3的自定义字体@font-face 规则的工作原理 使用@font-face规则初看起来非常简单.从本质上看,它只需要两个步骤. 首先,使用 ...
- Hive Map 端OOM 异常
怪异现象:数据量不大,且不是Reduce端OOM,是Map端OOM Map Task运行的时候数据流中包含了非法字符例如:EOF.NOP等东西,导致BufferedReader读取和StreamDec ...
- jquery.qrcode二维码插件生成彩色二维码
jquery.qrcode.js 是居于jquery类库的绘制二维码的插件,用它来实现二维码图形渲染支持canvas和table两种绘图方式. (jquery.qrcode.js 设置显示方式为tab ...
- iOS 相关职位要求整理版
在拉勾上找了20家,BOSS直聘找了10家感兴趣的在招聘 iOS 程序员的公司,把职位要求整理了一下. 初创公司一般要求1年以上开发经验,成长型或者成熟型公司一般要求最低2年以上开发经验.这里针对的是 ...
- android小知识之EditText输入框之值监控以及类型限制(数字,英语字母,下划线,是否为星号密码)
1.设置EditText的值监听事件 . <span style="font-size:14px;color:#990000;"> EditText ed=new Ed ...
- 激活工具 – Microsoft Toolkit 2.4.7
Microsoft Toolkit是一款很出名的Windows/Office激活工具,最早是因为激活Office 2010出名的,想必不少人也用过吧?Microsoft Toolkit从2.4.1版本 ...
- 使用tcpdump抓Android网络包
1 抓包原理 tcpdump(需Root用户运行)拦截和显示发送或收到过网络连接到该机器的TCP/IP和其他数据包.简单说就监控手机进出网络数据. 2 方法优劣 2.1优点 1.手机数据包无遗漏 2. ...
- Codeforces Round#344
A题意思是,给出两个数列,求一个区间,使第一个数列的区间或和第二个数列的区间或的和最大,输出最大和 很显然,或运算会使得答案越运算越大.所以,直接全部或起来,相加就是答案. = =打cf的时候自动脑补 ...
- linux下安装python3.3.4
下载安装包 # wget http://www.python.org/ftp/python/3.3.4/Python-3.3.4.tgz 解压 # tar -xzvf Python-3.3.4.tgz ...