题目传送门

  1. /*
  2. 题意:n个时刻点,m次时光穿梭,告诉的起点和终点,q次询问,每次询问t时刻t之前有多少时刻点是可以通过两种不同的路径到达
  3. 思维:对于当前p时间,从现在到未来穿越到过去的是有效的值,排个序,从大到小询问,那么之前添加的穿越点都是有效的,
  4. 用multiset保存。比赛时想到了排序,但是无法用线段树实现查询,stl大法好!
  5. */
  6. #include <cstdio>
  7. #include <algorithm>
  8. #include <cstring>
  9. #include <set>
  10. #include <iostream>
  11. using namespace std;
  12. const int MAXN = 1e5 + ;
  13. const int INF = 0x3f3f3f3f;
  14. struct Year {
  15. int u, v;
  16. bool operator < (const Year &r) const {
  17. return u > r.u;
  18. }
  19. }y[MAXN];
  20. struct Query {
  21. int p, id;
  22. bool operator < (const Query &r) const {
  23. return p > r.p;
  24. }
  25. }q[MAXN];
  26. int ans[MAXN];
  27. int a[];
  28. int n, m, l;
  29. int main(void) { //ZOJ Monthly, July 2015 - H Twelves Monkeys
  30. //freopen ("H.in", "r", stdin);
  31. while (scanf ("%d%d%d", &n, &m, &l) == ) {
  32. for (int i=; i<=m; ++i) {
  33. scanf ("%d%d", &y[i].u, &y[i].v);
  34. }
  35. for (int i=; i<=l; ++i) {
  36. scanf ("%d", &q[i].p); q[i].id = i;
  37. }
  38. sort (y+, y++m); sort (q+, q++l);
  39. multiset<int> S; int j = ;
  40. for (int i=; i<=l; ++i) {
  41. while (j <= m && y[j].u >= q[i].p) {
  42. S.insert (y[j].v); j++;
  43. }
  44. multiset<int>::iterator it; int cnt = ;
  45. for (it=S.begin (); it!=S.end (); ++it) {
  46. a[++cnt] = *(it); if (cnt == ) break;
  47. }
  48. if (cnt == && a[] <= q[i].p) ans[q[i].id] = q[i].p - a[];
  49. else ans[q[i].id] = ;
  50. }
  51. for (int i=; i<=l; ++i)
  52. printf ("%d\n", ans[i]);
  53. }
  54. return ;
  55. }

思维+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. T1003 电话连线 codevs

    http://codevs.cn/problem/1003/ 时间限制: 1 s  空间限制: 128000 KB  题目等级 : 黄金 Gold 题目描述 Description 一个国家有n个城市 ...

  2. cogs——1001. [WZOI2011 S3] 消息传递

    1001. [WZOI2011 S3] 消息传递 ★★   输入文件:messagew.in   输出文件:messagew.out   简单对比时间限制:1 s   内存限制:128 MB Prob ...

  3. 创建简单的spring-mvc项目

    1.第一步:创建项目 new—>Dynamic Web Project 项目创建成功后,展示如图: 2.第二步:导入springmvc的jar包和common-logging.jar 3.第三步 ...

  4. 解析excel文件并将数据导入到数据库中

    今天领导给安排了一个临时工作,让我将一个excel里面的数据解析后放入数据库中,经过一个下午的努力成功完成,现在将代码献上,希望对大家有所帮助 一.需要导入的jar 1.commons-collect ...

  5. 苹果Macbook Air怎么安装Win7系统图解教程

    下面开始我们在苹果Macbook Air上的Windows7之旅吧.

  6. ArcGIS Python 编码问题

    吐槽一下ArcGIS自带的 Python IDE, 没有代码补全 没有函数提示 没有代码折叠 没有行号 撤销操作还有问题 字符编码还有各种问题 .........   花了2天时间才琢磨出来的经验 环 ...

  7. C# .NET Visual Studio VS2008如何显示行号

    工具-选项,然后勾选"显示所有设置",然后在文本编辑器下面找到所有语言,勾选"行号"即可.  

  8. Oracle中长度为0字符串与null等价

    不试不知道,Oracle中,长度为0的字符串'' 居然与null等价! 众所周知,null代表空,什么都不存在,而一个字符串'',虽然长度为0,但毕竟已经是一个字符串,二者怎么能等价,混为一谈呢. 在 ...

  9. poj1151==codevs 3044 矩形面积求并

    Atlantis Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 21511   Accepted: 8110 Descrip ...

  10. 【bzoj1303】[CQOI2009]中位数图

    一个大于b的数和一个小于b的数可以互相抵消,所以我们用1和-1表示. 从b向两边扩展,left[i]表示b左边抵消后有i个数比b小的可能数,right[i]表示b右边抵消后有i个数比b大的可能数. a ...