题目传送门

 /*
题意:n个时刻点,m次时光穿梭,告诉的起点和终点,q次询问,每次询问t时刻t之前有多少时刻点是可以通过两种不同的路径到达
思维:对于当前p时间,从现在到未来穿越到过去的是有效的值,排个序,从大到小询问,那么之前添加的穿越点都是有效的,
用multiset保存。比赛时想到了排序,但是无法用线段树实现查询,stl大法好!
*/
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <set>
#include <iostream>
using namespace std; const int MAXN = 1e5 + ;
const int INF = 0x3f3f3f3f;
struct Year {
int u, v;
bool operator < (const Year &r) const {
return u > r.u;
}
}y[MAXN];
struct Query {
int p, id;
bool operator < (const Query &r) const {
return p > r.p;
}
}q[MAXN];
int ans[MAXN];
int a[];
int n, m, l; int main(void) { //ZOJ Monthly, July 2015 - H Twelves Monkeys
//freopen ("H.in", "r", stdin); while (scanf ("%d%d%d", &n, &m, &l) == ) {
for (int i=; i<=m; ++i) {
scanf ("%d%d", &y[i].u, &y[i].v);
}
for (int i=; i<=l; ++i) {
scanf ("%d", &q[i].p); q[i].id = i;
} sort (y+, y++m); sort (q+, q++l);
multiset<int> S; int j = ;
for (int i=; i<=l; ++i) {
while (j <= m && y[j].u >= q[i].p) {
S.insert (y[j].v); j++;
}
multiset<int>::iterator it; int cnt = ;
for (it=S.begin (); it!=S.end (); ++it) {
a[++cnt] = *(it); if (cnt == ) break;
}
if (cnt == && a[] <= q[i].p) ans[q[i].id] = q[i].p - a[];
else ans[q[i].id] = ;
}
for (int i=; i<=l; ++i)
printf ("%d\n", ans[i]);
} return ;
}

思维+multiset ZOJ Monthly, July 2015 - H Twelves Monkeys的更多相关文章

  1. Twelves Monkeys (multiset解法 141 - ZOJ Monthly, July 2015 - H)

    Twelves Monkeys Time Limit: 5 Seconds      Memory Limit: 32768 KB James Cole is a convicted criminal ...

  2. ZOJ 3913 Bob wants to pour water ZOJ Monthly, October 2015 - H

    Bob wants to pour water Time Limit: 2 Seconds      Memory Limit: 65536 KB      Special Judge There i ...

  3. ZOJ 3910 Market ZOJ Monthly, October 2015 - H

    Market Time Limit: 2 Seconds      Memory Limit: 65536 KB There's a fruit market in Byteland. The sal ...

  4. ZOJ Monthly, July 2015

    B http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5552 输入n,表示有n个数1到n.A先拿,B后拿,依次拿,每次可以拿任意一 ...

  5. ZOJ 3908 Number Game ZOJ Monthly, October 2015 - F

    Number Game Time Limit: 2 Seconds      Memory Limit: 65536 KB The bored Bob is playing a number game ...

  6. 143 - ZOJ Monthly, October 2015 I Prime Query 线段树

    Prime Query Time Limit: 1 Second      Memory Limit: 196608 KB You are given a simple task. Given a s ...

  7. ZOJ 3911 Prime Query ZOJ Monthly, October 2015 - I

    Prime Query Time Limit: 1 Second      Memory Limit: 196608 KB You are given a simple task. Given a s ...

  8. ZOJ 3905 Cake ZOJ Monthly, October 2015 - C

    Cake Time Limit: 4 Seconds      Memory Limit: 65536 KB Alice and Bob like eating cake very much. One ...

  9. ZOJ 3903 Ant ZOJ Monthly, October 2015 - A

    Ant Time Limit: 1 Second      Memory Limit: 32768 KB There is an ant named Alice. Alice likes going ...

随机推荐

  1. 重启系统media服务

    1.adb shell 执行 stop media & start media 或者stop media ; start media 2.代码里执行 import android.os.Sys ...

  2. POJ3295 Tautology 解题报告

    直接上分析: 首先 弄清各种大写字母的操作的实质 K 明显 是 and   & A 是 or      | N 是 not   ! C  由表格注意到 当 w<=x 时 值为1 E  当 ...

  3. <项目><day11>查看用户浏览过的商品

    <项目>查看用户浏览过的商品 1.创建一个entity包储存实体对象 1.1创建一个Product的类存储实体对象 对象具有以下属性,并添加set和get方法,含参和不含参的构造方法,to ...

  4. ios截屏事件监听

    目的:实现截屏反馈,类似支付宝的截屏上传反馈功能. 1.注册全局通知,在Appdelegate中注册截屏监听通知 - (void)registNotification{ [[NSNotificatio ...

  5. windows安装docker

    主要參考:http://docs.docker.com/installation/windows/ [1]安装完毕后同意后可能会报错: error in run: Failed to start ma ...

  6. POJ 1849 Two(遍历树)

    POJ 1849 Two(遍历树) http://poj.org/problem?id=1849 题意: 有一颗n个结点的带权的无向树, 在s结点放两个机器人, 这两个机器人会把树的每条边都走一遍, ...

  7. 扩展GCD 中国剩余定理(CRT) 乘法逆元模版

    extend_gcd: 已知 a,b (a>=0,b>=0) 求一组解 (x,y) 使得 (x,y)满足 gcd(a,b) = ax+by 以下代码中d = gcd(a,b).顺便求出gc ...

  8. Boss OpenCart 商城自适应主题模板 ABC-0012-01

    Boss OpenCart 商城自适应主题模板 ABC-0012-01 模板特性兼容浏览器IE7, IE8, IE9, IE10, Firefox, Safari, Chrome OpenCart版本 ...

  9. Binary Tree Maximum Path Sum 自底向上求解(重重重重)

    题目: 链接 解答: 自底向上求解.left_max right_max分别返回了左右子树的最大路径和,假设左右子树最大路径和小于0.那么返回零. 用这个最大路径和和根节点的值相加.来更新最大值,同一 ...

  10. 省市联动选择的一个demo,利用vue+webpack+amaze-vue实现省市区联动选择组件

    https://github.com/sunshineJi/vue-city-picker