ZOJ 3888 Twelves Monkeys
Twelves Monkeys
This problem will be judged on ZJU. Original ID: 3888
64-bit integer IO format: %lld Java class name: Main
James Cole is a convicted criminal living beneath a post-apocalyptic Philadelphia. Many years ago, the Earth's surface had been contaminated by a virus so deadly that it forced the survivors to move underground. In the years that followed, scientists had engineered an imprecise form of time travel. To earn a pardon, Cole allows scientists to send him on dangerous missions to the past to collect information on the virus, thought to have been released by a terrorist organization known as the Army of the Twelve Monkeys.
The time travel is powerful so that sicentists can send Cole from year x[i] back to year y[i]. Eventually, Cole finds that Goines is the founder of the Army of the Twelve Monkeys, and set out in search of him. When they find and confront him, however, Goines denies any involvement with the viruscan. After that, Cole goes back and tells scientists what he knew. He wants to quit the mission to enjoy life. He wants to go back to the any year before current year, but scientists only allow him to use time travel once. In case of failure, Cole will find at least one route for backup. Please help him to calculate how many years he can go with at least two routes.
Input
The input file contains multiple test cases.
The first line contains three integers n,m,q(1≤ n ≤ 50000, 1≤ m ≤ 50000, 1≤ q ≤ 50000), indicating the maximum year, the number of time travel path and the number of queries.
The following m lines contains two integers x,y(1≤ y ≤ x ≤ 50000) indicating Cole can travel from year x to year y.
The following q lines contains one integers p(1≤ p ≤ n) indicating the year Cole is at now
Output
For each test case, you should output one line, contain a number which is the total number of the year Cole can go.
Sample Input
9 3 3
9 1
6 1
4 1
6
7
2
Sample Output
5
0
1
Hint
6 can go back to 1 for two route.
One is 6-1, the other is 6-7-8-9-1. 6 can go back to 2 for two route.
One is 6-1-2, the other is 6-7-8-9-1-2.
Source
Author
#include <bits/stdc++.h>
using namespace std;
const int maxn = ;
struct QU {
int id,year;
bool operator<(const QU &t)const {
if(year == t.year) return id < t.id;
return year > t.year;
}
} Q[maxn];
int c[maxn];
vector<int>g[maxn];
void add(int i,int val) {
while(i < maxn) {
c[i] += val;
i += i&-i;
}
}
int sum(int i,int ret = ) {
while(i > ) {
ret += c[i];
i -= i&-i;
}
return ret;
}
int query(int low = ,int high = maxn-,int ret = -) {
while(low <= high) {
int mid = (low + high)>>;
if(sum(mid) >= ) {
ret = mid;
high = mid-;
} else low = mid + ;
}
return ret;
}
int ans[maxn];
int main() {
int n,m,q,x,y;
while(~scanf("%d%d%d",&n,&m,&q)) {
for(int i = ; i < maxn; ++i) g[i].clear();
memset(c,,sizeof c);
memset(ans,,sizeof ans);
for(int i = ; i < m; ++i) {
scanf("%d%d",&x,&y);
g[x].push_back(y);
}
for(int i = ; i < q; ++i) {
scanf("%d",&Q[i].year);
Q[i].id = i;
}
sort(Q,Q+q);
int now = ;
for(int i = n; i >= ; --i) {
for(int j = g[i].size()-; j >= ; --j)
add(g[i][j],);
if(Q[now].year == i) {
int idx = query(,i-);
if(idx == -) ans[Q[now].id] = ;
else ans[Q[now].id] = i - idx;
if(++now == q) break;
}
}
for(int i = ; i < q; ++i)
printf("%d\n",ans[i]);
}
return ;
}
ZOJ 3888 Twelves Monkeys的更多相关文章
- ZOJ 3888 Twelves Monkeys (预处理+优先队列)
题目链接:ZOJ 3888 Twelves Monkeys 题意:题目描写叙述起来比較绕,直接讲案例 9 3 3 9 1 6 1 4 1 6 7 2 输入n,m,q.n限制了你询问的年份,m台时光机, ...
- zoj 3888 Twelves Monkeys 二分+线段树维护次小值
链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do? problemCode=3888 Twelves Monkeys Time Limit: 5 ...
- 思维+multiset ZOJ Monthly, July 2015 - H Twelves Monkeys
题目传送门 /* 题意:n个时刻点,m次时光穿梭,告诉的起点和终点,q次询问,每次询问t时刻t之前有多少时刻点是可以通过两种不同的路径到达 思维:对于当前p时间,从现在到未来穿越到过去的是有效的值,排 ...
- 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 ...
- [主席树 强制在线]ZOJ3888 Twelves Monkeys
题意:有n年,其中m年可以乘时光机回到过去,q个询问 下面m行,x,y 表示可以在y年穿越回x年, 保证y>x 下面q个询问, 每个询问有个年份k 问的是k年前面 有多少年可以通过一种以上($\ ...
- zoj 3888 线段树 ***
卡n^2,用线段树降到nlogn 记录每个点上所覆盖线段的次小值,保证能有两条路径能走 #include<cstdio> #include<iostream> #include ...
- ZOJ 2334 Monkey King
并查集+左偏树.....合并的时候用左偏树,合并结束后吧父结点全部定成树的根节点,保证任意两个猴子都可以通过Find找到最厉害的猴子 Monkey King ...
- ZOJ People Counting
第十三届浙江省大学生程序设计竞赛 I 题, 一道模拟题. ZOJ 3944http://www.icpc.moe/onlinejudge/showProblem.do?problemCode=394 ...
- ZOJ 3686 A Simple Tree Problem
A Simple Tree Problem Time Limit: 3 Seconds Memory Limit: 65536 KB Given a rooted tree, each no ...
随机推荐
- webbench压力測试工具
apache的測试工具ab 在并发100个以上后会出现错误.网上也有非常多改ab源代码来解禁的. 只是还是推荐一款比較好用的压力測试工具webbench wget http://blog.zyan.c ...
- golang自己定义数据类型查询与插入postgresql中point数据
golang自己定义数据类型查询与插入postgresql中point数据 详细代码例如以下: package main import ( "bytes" "databa ...
- ubuntu查看文件大小
使用linux命令df 和du,df 但是df只能查看一级文件夹大小.使用比例.档案系统及其挂入点,但对文件却无能为力.du可以查看文件及文件夹的大小.所以基本上是两者配合使用. 一 df h参数, ...
- curl ,post,get (原创)
curl get: 1)直接输出 $ch=curl_init(); curl_setopt($ch,CURLOPT_URL,"http://testopen.api.yaolan.com/a ...
- 自己实现的一个 .net 缓存类(原创)
public class CacheContainer { private static Hashtable ht = new Hashtable(); /// <summary> /// ...
- git 本地项目推送至远程仓库
1 在本地文件夹下创建一个 Git 仓库(如test目录下) git init 2 此时test文件夹即是你的maste主分支,你可以在改文件夹下写自己的项目 3 将test文件夹下的内容提交至暂存区 ...
- getElementsByName使用
查了下手册,getElementsByName()不能提取没有name属性的标签.div标签本身没有name属性,所以不能被提取.有name标签的主要是各种input标签,所以默认情况下getElem ...
- Android之MVP架构
MVP(Model View Presenter)模式是由MVC模式发展而来的,在如今的Android程序开发中显得越来越重要.本篇文章简单讨论了MVP模式的思想. 啥是MVP MVP模式的主要思想是 ...
- 函数的arguments
1.arguments a.只能在函数内部被访问. b.arguments是一个伪数组(有下标索引,可以存放多个值,但是他里面没有数组的方法.) c.arguments里面存的是什么?函数的实际参数传 ...
- html行级元素和块级元素以及css转换
之前有说过html的标签是有语义的,当然也就有一些默认的样式,比如标题有h1···h6,他们的字体由大至小一次递减,字体比一般字体要加粗. 这样也就有了行级元素和块级元素,下面来看看什么是行级元素什么 ...