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 线段树的更多相关文章

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

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

  2. codeforces 609F. Frogs and mosquitoes 二分+线段树

    题目链接 F. Frogs and mosquitoes time limit per test 2 seconds memory limit per test 512 megabytes input ...

  3. codeforces Good bye 2016 E 线段树维护dp区间合并

    codeforces Good bye 2016 E 线段树维护dp区间合并 题目大意:给你一个字符串,范围为‘0’~'9',定义一个ugly的串,即串中的子串不能有2016,但是一定要有2017,问 ...

  4. codeforces 22E XOR on Segment 线段树

    题目链接: http://codeforces.com/problemset/problem/242/E E. XOR on Segment time limit per test 4 seconds ...

  5. Codeforces 588E. A Simple Task (线段树+计数排序思想)

    题目链接:http://codeforces.com/contest/558/problem/E 题意:有一串字符串,有两个操作:1操作是将l到r的字符串升序排序,0操作是降序排序. 题解:建立26棵 ...

  6. Codeforces Gym 100803G Flipping Parentheses 线段树+二分

    Flipping Parentheses 题目连接: http://codeforces.com/gym/100803/attachments Description A string consist ...

  7. Codeforces GYM 100114 D. Selection 线段树维护DP

    D. Selection Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100114 Descriptio ...

  8. Codeforces 444C DZY Loves Colors(线段树)

    题目大意:Codeforces 444C DZY Loves Colors 题目大意:两种操作,1是改动区间上l到r上面德值为x,2是询问l到r区间总的改动值. 解题思路:线段树模板题. #inclu ...

  9. Codeforces 85D Sum of Medians(线段树)

    题目链接:Codeforces 85D - Sum of Medians 题目大意:N个操作,add x:向集合中加入x:del x:删除集合中的x:sum:将集合排序后,将集合中全部下标i % 5 ...

随机推荐

  1. nginx 403 forbidden

    2018年3月9日14:11:59 总结一下: 1. 查看目录或者文件是否是可读可执行 2. 查看nginx配置的server -> location -> index指令, 看其列出的入 ...

  2. Centos 6.5 freeswitch 编译mod_shout

    1. yum install -y patch 2. yum install -y libshout-devel lame-devel libmpg123-devel 3. make install ...

  3. ebs 12.1.1 单节点多用户安装

    本次测试环境:操作系统 oracle linux 6.9   oracle ebs 12.1.1   192.168.20.210  erpapp1.hthorizon.com erpapp1 yum ...

  4. 新手-ios

    最近突然让我学习一下ios,之前从未接触过(一脸蒙逼).而且我用的电脑也不是ios操作系统.上网查了下 网友说虚拟机也可以,于是本人从此举用上了ios系统. 需要的安装的工具有: 资源共享给大家: h ...

  5. oracle数据库链路和同义词

    Oracle数据库链路的建立和使用 先来一个例子: --创建数据库链路create   public   database link xaffdblink connect to zdcl identi ...

  6. zxing源码编译与运行

    编译的jar文件下载地址:http://files.cnblogs.com/rainboy2010/zxing.zip zxing是一个开源的解析条形码/二维码的类库,广泛应用于Android 各大A ...

  7. 24)django-信号

    目录 1)django信号简介 2)django内置信号 3)django自定义信号 一:django信号简介 Django中提供了“信号调度”,用于在框架执行操作时解耦. 通俗来讲,就是一些动作发生 ...

  8. Confluence 6 用户目录图例 - Confluence 内部目录

    上面的图:Confluence 使用内部目录为用户管理. https://www.cwiki.us/display/CONFLUENCEWIKI/Diagrams+of+Possible+Config ...

  9. linux下命令窗口中$和#的区别

    $表示现在的用户是普通用户#表示现在的用户是root用户 # 代表你能做任何事$ 代表你能做一些/下和/home目录的所有事

  10. Niagara 泵阀

    1.泵阀系统 2.Niagara 每次在启动workbench的时候安装一下daemon,后启动platform 启动station的时候,当station的status变成Running之后启动