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. [POSIX]文件系统(概述)

    1.文件名由除系统目录分隔符(unix是/,windows是\)和空字符“\0”外的任意ASCII字符组成,现代系统很多还可以包含UNICODE字符,但是还是推荐使用传统的ASCII码命名. 2.目录 ...

  2. Java并发编程的4个同步辅助类(CountDownLatch、CyclicBarrier、Semaphore、Phaser)

    我在<JDK1.5引入的concurrent包>中,曾经介绍过CountDownLatch.CyclicBarrier两个类,还给出了CountDownLatch的演示案例.这里再系统总结 ...

  3. 每天备份tomcat日志

    #!/bin/bash Backup_Home=/data/backup-log mkdir -p $Backup_Home Log_Home=/data/Tomcat/logs App_Log_Ho ...

  4. 【进阶4-2期】Object.assign 原理及其实现 (转)

    这是我在公众号(高级前端进阶)看到的文章,现在做笔记  https://github.com/yygmind/blog/issues/26 浅拷贝 Object.assign 上篇文章介绍了其定义和使 ...

  5. mabytis的xml一些写法

    1.jdbcType=TIMESTAMP 而不是 jdbcType=DATETIME myabtis 3.4.6 版本jar包中:jdbcType枚举: ARRAY(Types.ARRAY), BIT ...

  6. dict-test

    #! -*- coding:utf-8 -*-"""键必须是唯一的,但值则不必len(dict) 计算字典元素个数,即键的总数str(dict) 输出字典,以可打印的字符 ...

  7. Oracle Ora 错误解决方案合集

    注:本文来源于 < Oracle学习笔记 --- Oracle ORA错误解决方案 > ORA-00001: 违反唯一约束条件 (.)错误说明:当在唯一索引所对应的列上键入重复值时,会触发 ...

  8. Confluence 6 Home 和其他重要的目录

    Confluence 安装目录 Confluence 安装的目录(Confluence Installation directory)定义的是 Confluence 是在那里进行安装的.这个目录有时候 ...

  9. Confluence 6 € 欧元字符集不能正常显示

    € (euro) 标记 是一个 3 字节字符,在 (UTF-8)中这个字符被表示为 0xE2, 0x82, 0xAC. 有时候,你的系统中没有设置所有的地方为相同的字符集的时候(Confluence, ...

  10. Confluence 6 workbox 包含从 Jira 来的通知

    如果你的 Confluence 站点链接了一个 Jira 应用,你可以包含从 Jira 应用来的通知,例如 Jira 软化或 Jira 服务器桌面. 希望包含有从 Jira 应用来的通知: 你的 Ji ...