思维+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 ...
随机推荐
- 【进击后端】linux安装最新版nodejs
nodejs下载:https://nodejs.org/zh-cn/download/ 1.cd /root/download 2.wget https://nodejs.org/dist/v6.11 ...
- MongoDB小结03 - insert、remove
连接MongoDB(bin目录下) ./mongo 如果觉得shell里空空的可以输入help,在刷屏的同时大致了解下有哪些方法 help 现在咱们还没有数据库,咱们创建一个,任性起名:templat ...
- JavaScript错误处理和堆栈追踪
转自:https://github.com/dwqs/blog/issues/49 有时我们会忽略错误处理和堆栈追踪的一些细节, 但是这些细节对于写与测试或错误处理相关的库来说是非常有用的. 例如这周 ...
- 小白学开发(iOS)OC_ 字符串的获取 (2015-08-11)
// // main.m // 字符串的获取 // // Created by admin on 15/8/13. // Copyright (c) 2015年 admin. All righ ...
- react 项目实战(三)表单验证
我们需要记录每一个字段当前的有效状态,有效时隐藏错误信息,无效时显示错误信息. 而这个有效/无效,可以在表单值改变的时候进行判断. 我们对/src/pages/UserAdd.js进行修改: 首先修改 ...
- rsh 无秘钥登陆配置
/etc/hosts.equiv里的主机不须要提供password就能够訪问本机./etc/host.equiv 要和~/.rhosts文件连用. [root@web-htl2-01 ~]# cat ...
- Java:String和Date、Timestamp之间的转换【转】
原文地址:http://yunnick.iteye.com/blog/1074495 一.String与Date(java.util.Date)互转 1.1 String -> Date Str ...
- 解决ubuntu中firefox浏览器总是提示找不到server的问题
这个情况在我机器上常常出现,并且时不时的给你出点问题.可是有些时候等一下就好了.或者把引擎换到百度的话它就又行得通了.. 被这个问题搞得非常烦.上网查了下说是防火墙啊之类的出问题.可是自己弄了后这个问 ...
- Codeforces Round #228 (Div. 2) C. Fox and Box Accumulation
C. Fox and Box Accumulation time limit per test 1 second memory limit per test 256 megabytes input s ...
- Bootstrap4 网格系统
学习注意事项 col-*-* 第一个*是设备类型,第二个*是控件宽度的占比 屏幕被等分为12,col-1宽度是1/12,col-6宽度是50%,col-12宽度是100% 给应用了class的elem ...