思维+multiset ZOJ Monthly, July 2015 - H Twelves Monkeys
/*
题意:n个时刻点,m次时光穿梭,告诉的起点和终点,q次询问,每次询问t时刻t之前有多少时刻点是可以通过两种不同的路径到达
思维:对于当前p时间,从现在到未来穿越到过去的是有效的值,排个序,从大到小询问,那么之前添加的穿越点都是有效的,
用multiset保存。比赛时想到了排序,但是无法用线段树实现查询,stl大法好!
*/
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <set>
#include <iostream>
using namespace std; const int MAXN = 1e5 + ;
const int INF = 0x3f3f3f3f;
struct Year {
int u, v;
bool operator < (const Year &r) const {
return u > r.u;
}
}y[MAXN];
struct Query {
int p, id;
bool operator < (const Query &r) const {
return p > r.p;
}
}q[MAXN];
int ans[MAXN];
int a[];
int n, m, l; int main(void) { //ZOJ Monthly, July 2015 - H Twelves Monkeys
//freopen ("H.in", "r", stdin); while (scanf ("%d%d%d", &n, &m, &l) == ) {
for (int i=; i<=m; ++i) {
scanf ("%d%d", &y[i].u, &y[i].v);
}
for (int i=; i<=l; ++i) {
scanf ("%d", &q[i].p); q[i].id = i;
} sort (y+, y++m); sort (q+, q++l);
multiset<int> S; int j = ;
for (int i=; i<=l; ++i) {
while (j <= m && y[j].u >= q[i].p) {
S.insert (y[j].v); j++;
}
multiset<int>::iterator it; int cnt = ;
for (it=S.begin (); it!=S.end (); ++it) {
a[++cnt] = *(it); if (cnt == ) break;
}
if (cnt == && a[] <= q[i].p) ans[q[i].id] = q[i].p - a[];
else ans[q[i].id] = ;
}
for (int i=; i<=l; ++i)
printf ("%d\n", ans[i]);
} return ;
}
思维+multiset ZOJ Monthly, July 2015 - H Twelves Monkeys的更多相关文章
- 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 ...
- 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 ...
- 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 ...
- ZOJ Monthly, July 2015
B http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5552 输入n,表示有n个数1到n.A先拿,B后拿,依次拿,每次可以拿任意一 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
随机推荐
- 【BZOJ2301】Problem b(莫比乌斯反演)
题意:对于给出的n个询问,每次求有多少个数对(x,y),满足a≤x≤b,c≤y≤d, 且gcd(x,y) = k,gcd(x,y)函数为x和y的最大公约数. 1≤n≤50000,1≤a≤b≤50000 ...
- FZU Problem 2132 LQX的作业 (数学题)
http://acm.fzu.edu.cn/problem.php?pid=2132 N个数已经排成非递减顺序,那么每次可以取 前m->n个在x前面.取前m个在x前面的概率是 C(n,m)*x^ ...
- pandas中计算总体标准差
标准差(或方差),分为 总体标准差(方差)和 样本标准差(方差). 前者分母为n,后者为n-1.后者是无偏的. pandas里的 .std() 和 .var() 都是算的无偏的. 而numpy是有偏的 ...
- Nginx教程收集
学习要系统,最推荐的方式是看书. 下面是收集的一些Nginx教程: https://www.gitbook.com/book/yinsigan/nginx/details http://www.ngi ...
- mvnw是什么(Maven Wrapper/Maven保持构建工具版本一直的工具)
背景 Maven是一款非常流行的Java项目构建软件,它集项目的依赖管理.测试用例运行.打包.构件管理于一身,是我们工作的好帮手,maven飞速发展,它的发行版本也越来越多,如果我们的项目是基于Mav ...
- 我的arcgis培训照片4 来自http://www.cioiot.com/successview-549-1.html
- TP-Link的Atheros芯片的WR886n v5 安装SuperWRT系统
安装SuperWRT系统 本教程以TP-Link的Atheros芯片的WR886n v5为例,教新手如何刷入一个已支持设备的固件. 下载设备固件请访问:这里 (没有支持你的设备?自由动手一下:hack ...
- UML中的四种关系总结
UML中的关系主要包含四种:关联关系.依赖关系.泛化关系.实现关系.当中关联关系还包含聚合关系和组合关系. 1. 关联关系(Association) 关联关系式一种结构化的关系,是指一种对象和还有一种 ...
- DirectX11 学习笔记7 - 支持自由移动的摄像机
如今将又一次制定一个camera摄像机.能够自由移动. 比方前进 后退,上游 下潜. 各个方向渲染之类的. 首先设置按键. 这个时候须要在 XWindow.h 里面 bool XWindow::fra ...
- C++求解数组中出现超1/4的三个数字。
#include <iostream> using namespace std; //求x!中k因数的个数. int Grial(int x,int k) { int Ret = 0; w ...