Twelves Monkeys

Time Limit: 5000ms
Memory Limit: 32768KB

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

GAN, Tiansheng
 
解题:离线二分BIT
 
 #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的更多相关文章

  1. 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台时光机, ...

  2. zoj 3888 Twelves Monkeys 二分+线段树维护次小值

    链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do? problemCode=3888 Twelves Monkeys Time Limit: 5 ...

  3. 思维+multiset ZOJ Monthly, July 2015 - H Twelves Monkeys

    题目传送门 /* 题意:n个时刻点,m次时光穿梭,告诉的起点和终点,q次询问,每次询问t时刻t之前有多少时刻点是可以通过两种不同的路径到达 思维:对于当前p时间,从现在到未来穿越到过去的是有效的值,排 ...

  4. 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 ...

  5. [主席树 强制在线]ZOJ3888 Twelves Monkeys

    题意:有n年,其中m年可以乘时光机回到过去,q个询问 下面m行,x,y 表示可以在y年穿越回x年, 保证y>x 下面q个询问, 每个询问有个年份k 问的是k年前面 有多少年可以通过一种以上($\ ...

  6. zoj 3888 线段树 ***

    卡n^2,用线段树降到nlogn 记录每个点上所覆盖线段的次小值,保证能有两条路径能走 #include<cstdio> #include<iostream> #include ...

  7. ZOJ 2334 Monkey King

    并查集+左偏树.....合并的时候用左偏树,合并结束后吧父结点全部定成树的根节点,保证任意两个猴子都可以通过Find找到最厉害的猴子                       Monkey King ...

  8. ZOJ People Counting

    第十三届浙江省大学生程序设计竞赛 I 题, 一道模拟题. ZOJ  3944http://www.icpc.moe/onlinejudge/showProblem.do?problemCode=394 ...

  9. ZOJ 3686 A Simple Tree Problem

    A Simple Tree Problem Time Limit: 3 Seconds      Memory Limit: 65536 KB Given a rooted tree, each no ...

随机推荐

  1. linux命令用来查看日志关键字

    1.查看日志 前 n行: cat 文件名 | head -n 数量 demo: cat  test.log | head -n 200 # 查看test.log前200行 2.查看日志 尾 n行: c ...

  2. java中tcp小样例

    服务端: ServerSocket service = new ServerSocket(7777); Socket socket = service.accept(); InputStream in ...

  3. andoid电阻触摸移植

    这里我使用的是210的开发板 系统Android4.0.4 内核linux3.0.8 要用电阻屏一般都是使用tslib进行校准的 这里给个我在android上用的tslib 下载地址 http://d ...

  4. 利用 Gearman 实现系统错误报警功能

    Gearman 是什么? Gearman是一个用来把工作委派给其他机器.分布式的调用更适合做某项工作的机器.并发的做某项工作在多个调用间做负载均衡.或用来在调用其它语言的函数的系统. Gearman ...

  5. xcode Could not launch "" ; has denied the launch request

    xcode Could not launch "" ;  “”“ has denied the launch request  (注意,这种方式不能调试) 1.编辑scheme 2 ...

  6. 国内物联网平台初探(三) ——QQ物联·智能硬件开放平台

    平台定位 将QQ帐号体系.好友关系链.QQ消息通道及音视频服务等核心能力提供给可穿戴设备.智能家居.智能车载.传统硬件等领域的合作伙伴,实现用户与设备.设备与设备.设备与服务之间的联动. 实现用户与设 ...

  7. docker(部署常见应用):docker部署redis

    上节回顾:docker(部署常见应用):docker部署mysql docker部署redis:4.0 # 下载镜像 docker pull redis:4.0 # 查看下载镜像 docker ima ...

  8. SQLServer 添加序号列

    select ROW_NUMBER()OVER(ORDER BY 用来排序的列的列名),XXX,XXX from XXX 按照原始顺序: ROW_NUMBER()OVER(ORDER BY (sele ...

  9. 关于百分比宽高div居中并垂直居中问题

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  10. 如何用PYTHON代码写出音乐

    什么是MIDI 博主本人虽然五音不全,而且唱歌还很难听,但是还是非常喜欢听歌的.我一直在做这样的尝试,就是通过人工智能算法实现机器自动的作词和编曲(在这里预告下,通过深度学习写歌词已经实现了,之后会分 ...