博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
ZOJ 3888 Twelves Monkeys
阅读量:5076 次
发布时间:2019-06-12

本文共 4006 字,大约阅读时间需要 13 分钟。

Twelves Monkeys

Time Limit: 5000ms
Memory Limit: 32768KB
This problem will be judged on 
ZJU. Original ID: 
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 39 16 14 1672

Sample Output

501

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
 
1 #include 
2 using namespace std; 3 const int maxn = 100001; 4 struct QU { 5 int id,year; 6 bool operator<(const QU &t)const { 7 if(year == t.year) return id < t.id; 8 return year > t.year; 9 }10 } Q[maxn];11 int c[maxn];12 vector
g[maxn];13 void add(int i,int val) {14 while(i < maxn) {15 c[i] += val;16 i += i&-i;17 }18 }19 int sum(int i,int ret = 0) {20 while(i > 0) {21 ret += c[i];22 i -= i&-i;23 }24 return ret;25 }26 int query(int low = 1,int high = maxn-1,int ret = -1) {27 while(low <= high) {28 int mid = (low + high)>>1;29 if(sum(mid) >= 2) {30 ret = mid;31 high = mid-1;32 } else low = mid + 1;33 }34 return ret;35 }36 int ans[maxn];37 int main() {38 int n,m,q,x,y;39 while(~scanf("%d%d%d",&n,&m,&q)) {40 for(int i = 0; i < maxn; ++i) g[i].clear();41 memset(c,0,sizeof c);42 memset(ans,0,sizeof ans);43 for(int i = 0; i < m; ++i) {44 scanf("%d%d",&x,&y);45 g[x].push_back(y);46 }47 for(int i = 0; i < q; ++i) {48 scanf("%d",&Q[i].year);49 Q[i].id = i;50 }51 sort(Q,Q+q);52 int now = 0;53 for(int i = n; i >= 1; --i) {54 for(int j = g[i].size()-1; j >= 0; --j)55 add(g[i][j],1);56 if(Q[now].year == i) {57 int idx = query(1,i-1);58 if(idx == -1) ans[Q[now].id] = 0;59 else ans[Q[now].id] = i - idx;60 if(++now == q) break;61 }62 }63 for(int i = 0; i < q; ++i)64 printf("%d\n",ans[i]);65 }66 return 0;67 }
View Code

 

转载于:https://www.cnblogs.com/crackpotisback/p/4755641.html

你可能感兴趣的文章
动态规划算法之最大子段和
查看>>
linux c:关联变量的双for循环
查看>>
深入浅出理解zend framework(三)
查看>>
python语句----->if语句,while语句,for循环
查看>>
javascript之数组操作
查看>>
LinkedList源码分析
查看>>
TF-IDF原理
查看>>
用JS制作博客页面背景随滚动渐变的效果
查看>>
JavaScript的迭代函数与迭代函数的实现
查看>>
一步步教你学会browserify
查看>>
Jmeter入门实例
查看>>
亲近用户—回归本质
查看>>
中文脏话识别的解决方案
查看>>
CSS之不常用但重要的样式总结
查看>>
Python编译错误总结
查看>>
URL编码与解码
查看>>
日常开发时遇到的一些坑(三)
查看>>
Eclipse 安装SVN插件
查看>>
深度学习
查看>>
TCP粘包问题及解决方案
查看>>