题目链接

F. Frogs and mosquitoes
time limit per test

2 seconds

memory limit per test

512 megabytes

input

standard input

output

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.

Input

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.

Output

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.

Sample test(s)
input
4 6
10 2
15 0
6 1
0 1
110 10
1 1
6 0
15 10
14 100
12 2
output
3 114
1 10
1 1
1 2
input
1 2
10 2
20 2
12 1
output
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 二分+线段树的更多相关文章

  1. Codeforces 609F Frogs and mosquitoes 线段树

    Frogs and mosquitoes 用线段树维护每个点覆盖的最小id, 用multiset维护没有吃的蚊子. #include<bits/stdc++.h> #define LL l ...

  2. [Educational Round 3][Codeforces 609F. Frogs and mosquitoes]

    这题拖了快一周_(:з」∠)_就把这货单独拿出来溜溜吧~ 本文归属:Educational Codeforces Round 3 题目链接:609F - Frogs and mosquitoes 题目 ...

  3. Codeforces 889F Letters Removing(二分 + 线段树 || 树状数组)

    Letters Removing 题意:给你一个长度为n的字符串,然后进行m次删除操作,每次删除区间[l,r]内的某个字符,删除后并且将字符串往前补位,求删除完之后的字符串. 题解:先开80个set ...

  4. Educational Codeforces Round 61 D 二分 + 线段树

    https://codeforces.com/contest/1132/problem/D 二分 + 线段树(弃用结构体型线段树) 题意 有n台电脑,只有一个充电器,每台电脑一开始有a[i]电量,每秒 ...

  5. HDU4614 Vases and Flowers 二分+线段树

    分析:感觉一看就是二分+线段树,没啥好想的,唯一注意,当开始摆花时,注意和最多能放的比大小 #include<iostream> #include<cmath> #includ ...

  6. J - Joseph and Tests Gym - 102020J (二分+线段树)

    题目链接:https://cn.vjudge.net/contest/283920#problem/J 题目大意:首先给你n个门的高度,然后q次询问,每一次询问包括两种操作,第一种操作是将当前的门的高 ...

  7. 【BZOJ-3110】K大数查询 整体二分 + 线段树

    3110: [Zjoi2013]K大数查询 Time Limit: 20 Sec  Memory Limit: 512 MBSubmit: 6265  Solved: 2060[Submit][Sta ...

  8. hdu6070 Dirt Ratio 二分+线段树

    /** 题目:hdu6070 Dirt Ratio 链接:http://acm.hdu.edu.cn/showproblem.php?pid=6070 题意:给定n个数,求1.0*x/y最小是多少.x ...

  9. [Codeforces 266E]More Queries to Array...(线段树+二项式定理)

    [Codeforces 266E]More Queries to Array...(线段树+二项式定理) 题面 维护一个长度为\(n\)的序列\(a\),\(m\)个操作 区间赋值为\(x\) 查询\ ...

随机推荐

  1. Minimum Inversion Number(归并排序)

    Minimum Inversion Number Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java ...

  2. Objective-C 类属性和方法的訪问权限

    OC中提供了4种訪问权限.@private, @public, @protected这三种和其它的C++, Java是一样的,@package这个訪问权限并非Java里的包訪问权限,OC中没有包的概念 ...

  3. golang之interface(接口)与 reflect 机制

    一.概述 什么是interface,简单的说,interface是一组method的组合,通过interface来定义对象的一组行为: interface类型定义了一组方法,如果某个对象实现了某个接口 ...

  4. ADO.NET FOR MySQL帮助类

    using System; using System.Collections; using System.Collections.Specialized; using System.Data; usi ...

  5. SQL Server索引进阶:第十三级,插入,更新,删除

    在第十级到十二级中,我们看了索引的内部结构,以及改变结构造成的影响.在本文中,继续查看Insert,update,delete和merge造成的影响.首先,我们单独看一下这四个命令. 插入INSERT ...

  6. oracle 11g导入导出

    数据的导入 1 将D:\daochu.dmp 中的数据导入 TEST数据库中.   imp system/manager@TEST  file=d:\daochu.dmp    上面可能有点问题,因为 ...

  7. Deep Learning(深度学习)学习笔记整理系列之(八)

    Deep Learning(深度学习)学习笔记整理系列 zouxy09@qq.com http://blog.csdn.net/zouxy09 作者:Zouxy version 1.0 2013-04 ...

  8. Replace不区分大小写

    private string ReplaceNoCase(string text, string oldValue, string newValue) { return System.Text.Reg ...

  9. ASP.NET MVC 音乐商店 - 目录

    这一个系列的内容来自微软的音乐商店 Music Store, 这是项目在 Codeplex 上的地址:http://mvcmusicstore.codeplex.com/. 这个项目使用 ASP.NE ...

  10. C++_基础_类和对象2

    内容: (1)构造函数 (2)初始化列表及其必要性 (3)支持自定义类型转换的构造函数 (4)this指针 (5)const对象和成员函数 (6)析构函数 1.构造函数1.1 格式: class 类名 ...