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\) 查询\ ...
随机推荐
- Numpy之ndarray与matrix
1. ndarray对象 ndarray是numpy中的一个N维数组对象,可以进行矢量算术运算,它是一个通用的同构数据多维容器,即其中的所有元素必须是相同类型的. 可以使用array函数创建数组,每个 ...
- a中国天气网pi(json格式)
http://m.weather.com.cn/data/101050101.html 此接口的回报格式例如以下 { "weatherinfo": { "city&quo ...
- Ext.Net 使用总结之查询条件中的起始日期
2.关于查询条件中起始日期的布局方式 首先上一张图,来展示一下我的查询条件的布局,如下: 大多数时候,我们的查询条件都是一个条件占一个格子,但也有不同的时候,如:查询条件是起始日期,则需要将这两个条件 ...
- 异常java.lang.IllegalStateException的解决
在初始化viewPagerAdapter时,显示异常.从网上找了找有两类这样的问题,一种是说给一个视图设置了两个父类,如: TextView tv = new TextView();layout.ad ...
- C# 想要程序文件移动 而数据保持相对位置
如果用的数据库是access数据库 可以把数据库文件放到bin\debug下面,引用相对位置就可以了 如果程序中有上载文件,而程序需要使用到该文件,那么我们最好也是引用相对文件,我们只需要在数据表中的 ...
- WPF属性与特性的映射(TypeConverter)
1,定义一个类 public class Human { public string Name { get; set; } public Human Child { get; set; } } 2在X ...
- 记录hyperic-hq搭建开发环境遇到的坑
这个星期接到一个新的任务:解决HQ(一个用JAVA开发的开源的运维监控平台)现在遇到的snmp升级到3.0后bug.公司用的HQ是4.6版本.于是,我把项目从gitlab上clone下来后,就开始了我 ...
- ACM题目:487-3279
题目是这样子的 Description Businesses like to have memorable telephone numbers. One way to make a telephone ...
- java——String的那边破事
经典的先看下面一段代码,请问最终创建几个对象,分别在哪里? String s0 = new String("luoliang.me"); String s1 = "luo ...
- 【LeetCode题意分析&解答】39. Combination Sum
Given a set of candidate numbers (C) and a target number (T), find all unique combinations in C wher ...