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 ...
随机推荐
- Android基础新手教程——3.4 TouchListener PK OnTouchEvent + 多点触碰
Android基础新手教程--3.4 TouchListener PK OnTouchEvent + 多点触碰 标签(空格分隔): Android基础新手教程 本节引言: 如题,本节给大家带来的是To ...
- 读取url中某个值
url="http://test.plus.1course.cn/Task/Display?id=25942" print(url) result=url.split('/')[- ...
- 【CSS】CSS画矩形、圆、半圆、弧形、半圆、小三角、疑问框
在网页中,常常会用到各种Icon,假设老是麻烦设计狮画出来不免有些不好意思,所以有时候我们也能够用CSS写出各种简单的形状.一来能够减轻他们的负担,二来也能够使用CSS替代图片.提高载入速度. 在网页 ...
- Cocos2d-x3.3beta0创建动画的3种方式
1.单独载入精灵对象 渲染效率低,浪费资源,不推荐用该方法.代码例如以下:注:代码仅仅需贴到HelloWorldScene.cpp中就可以. //First,单独渲染每个精灵帧 auto sprite ...
- HTTP缓存和CDN缓存
一 http缓存 1.1缓存的分类: http中具有缓存功能的是:1.浏览器缓存. 2.缓存代理服务器. 1.2 什么是缓存: http缓存的是指:当Web请求抵达缓存时, 如果本地有“已缓存的”副 ...
- Linux学习(二) wget命令的使用
近期在Linux下进行一些操作,在非常多地方都用到了wget这个命令,记录一下一些有关wget的使用方法: wget是在Linux下开发的开放源码的软件,作者是Hrvoje Niksic,后来被移植到 ...
- 为了世界的和平~一起上caioj~~~!
打Call~打Call~打Call~~~!!! 世界毁灭了你在哪???不要犹豫,快去caioj!!! 无比优质的oj,未来大牛的明智之选----就是caioj~~~
- 国外物联网平台初探(二) ——微软Azure IoT
平台定位 连接设备.其它 M2M 资产和人员,以便在业务和操作中更好地利用数据. 连接 IoT 设备 将所有设备连接到云,从这些设备接收大规模数据,以及管理这些设备的授权和限制. 在将设备连接到云和处 ...
- 3-3 第三天 Promise 如何使用
回调的方式来处理异步,目的是要保证一个执行顺序,先完成什么再去完成什么,它们的作用其实是相同的,显然回调更容易来书写,但是它难以维护,很容易遗漏错误处理代码而且无法使用return语句来返回这个值. ...
- Email非正则表达式的判断
判断一个邮件是否合法,我们除了可以使用正则表达四以外还可以利用,Email地址的规律进行判断,那么一个合法的Email有哪些要求昵?具体如下: 必须有@与. @必须在第一个.之前 @与.不能连在一起 ...