题目传送门

 /*
题意: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. NOIP2018普及游记

    我好弱啊,今年又是考pj啊 今年GD的又是在我们学校有考点(gzez) 考前其实还是蛮紧张的,毕竟考砸了就AFO了.我dp是真的弱,模拟赛连最长下降子序列都不会写,心想要是T3是dp就咕咕咕了.去年那 ...

  2. [转] 结构体file_operations

    原文地址: http://www.cnblogs.com/sunyubo/archive/2010/12/22/2282079.html 结构体file_operations在头文件 linux/fs ...

  3. 树形DP 树的最小支配集,最小点覆盖与最大独立集

    最小支配集: 从V中选取尽量少的点组成一个集合,让V中剩余的点都与取出来的点有边相连. (点) 最小点覆盖: 从V中选取尽量少的点组成一个集合V1,让所有边(u,v)中要么u属于V1,要么v属于V1 ...

  4. 洛谷——P1454 圣诞夜的极光

    P1454 圣诞夜的极光 题目背景 圣诞夜系列~~ 题目描述 圣诞老人回到了北极圣诞区,已经快到12点了.也就是说极光表演要开始了.这里的极光不是极地特有的自然极光景象.而是圣诞老人主持的人造极光. ...

  5. JDBC示例(增删查改)

    前提: 1.项目中引入MySQL的JAR包,POM参考如下配置: <!-- mysql-connector-java --> <!-- http://mvnrepository.co ...

  6. java.util.Scanner

    java.util.Scanner是Java5的新特征,主要功能是简化文本扫描.这个类最实用的地方表现在获取控制台输入,其他的功能都很鸡肋,尽管Java API文档中列举了大量的API方法,但是都不怎 ...

  7. jmeter的dubbo压测,依赖jar包要放到执行机的lib/ext下

    对于jmeter的dubbo压测场景的master-slave结构: 即master的jmeter进行任务的下发和报告的生成,slave进行任务的执行 因为dubbo压测需要依赖很多三方jar包,那么 ...

  8. iOS音频播放 (二):AudioSession 转

    原文出处 :http://msching.github.io/blog/2014/07/08/audio-in-ios-2/ 前言 本篇为<iOS音频播放>系列的第二篇. 在实施前一篇中所 ...

  9. 深度学习-theano-windows -cuda-环境搭建

    本文将具体介绍深度学习之cuda的环境搭建 工具:支持CUDA的显卡(安装cuda6.5),VS2013.Anaconda. 步骤: 1.安装cuda6.5 这个不具体介绍,网上有很多文章.注意选择你 ...

  10. JAVA编程思想(2) - 操作符(二)

    5. 直接常量 -一般来说,假设程序里使用了"直接常量",编译器能够准确的知道要生成什么样的类型.但有时候却是模棱两可的. 这时候须要我们对编译器进行适当的"指导&quo ...