题目链接

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. Largest Submatrix(动态规划)

    Largest Submatrix Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others ...

  2. Sublime Text 3:3114的安装(目前最新),插件emmet的安装

    随便一些好了. 直接英文版吧,建议不要找中文版,学习英语不是? https://www.sublimetext.com/3   下载 https://github.com/wbond/package_ ...

  3. Ado.net 类扩展属性

    .要扩展的类名字一样,2个类加(partial) 小例子: using System; using System.Collections.Generic; using System.Linq; usi ...

  4. java web简易网上书店项目系列,使用MVC模式(servlet+jstl+dbutils),开篇

    一. 针对很多java web初学者入门困难的问题,笔者利用一个小型web项目,一步一步的展示java web开发方法,每一个章节引入一些java web开发的重点知识,让同学们可以将java web ...

  5. 使用astyle格式化代码【脚本】

    astyle使用基础教程 http://cppblog.com/jokes000/articles/158838.html steps: (1) apt-get install astyle 或者去主 ...

  6. Windows 桌面边栏小工具开发入门

          准备为网站做一个桌面通知功能的工具,现在网上一般是html5+js的比较多.虽然html5+js现在是web的开发主流,但是我们应用一般是windows系统.并且应使用中,需要打开谷歌或其 ...

  7. Linux中的盘符问题

    在windows 中像 C.D.E.F这些都可以当盘符,就是说对应了我们所看到的C盘,D盘,E盘,F盘.然而是不是只能加26个硬盘了呢? 盘符到硬盘也只是一个对映关系,我们也是可以建立从一个文件夹到一 ...

  8. HortonWorks

    http://zh.hortonworks.com/products/hortonworks-sandbox/

  9. QT实现appendSheet(QAxObject的一种Add + Move的方法)

    一般地,熟悉VB.VC的同学都知道,要将新增的excel表单添加到表单的末尾,是很简单的事情,直接调用Add函数,传入对应的函数形参,就能实现将新增表单插入到末尾,但是通过QT的QAxObject实现 ...

  10. 宣布正式发布 Windows Azure Notification Hub,新增 SQL Server AlwaysOn 可用性组侦听器支持

    今天,我们非常高兴地宣布,针对使用 Windows Azure 的移动和企业开发人员推出一些新功能.这些新功能可以减少构建移动应用程序的开发时间和成本,并能帮助企业开发人员实现高可用性和全球业务连续性 ...