G. 神圣的 F2 连接着我们 线段树优化建图+最短路
这个题目和之前写的一个线段树优化建图是一样的。
B - Legacy CodeForces - 787D 线段树优化建图+dij最短路 基本套路
之前这个题目可以相当于一个模板,直接套用就可以了。
不过注意为了提高效率,在区间与区间之间建边的时候建了两个虚点。
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <queue>
#include <vector>
#include <string>
#include <algorithm>
#include <iostream>
#include <map>
#define inf 0x3f3f3f3f
#define inf64 0x3f3f3f3f3f3f3f3f
using namespace std;
typedef long long ll;
const int maxn = 2e5 + ;
int numa[maxn * ], numb[maxn * ], lefta[maxn * ], leftb[maxn * ];
int start[maxn], endss[maxn];
ll d[maxn * ], tot;
int n, m, p, q;
bool vis[maxn * ];
struct edge {
int from, to, dist;
edge(int from = , int to = , int dist = ) :from(from), to(to), dist(dist) {}
};
struct heapnode {
ll d;
int u;
heapnode(ll d = , int u = ) : d(d), u(u) {}
bool operator<(const heapnode &a) const {
return a.d < d;
}
}; vector<edge> vec;
vector<int> g[maxn * ]; void add(int u, int v, int w) {
vec.push_back(edge(u, v, w));
int m = vec.size();
g[u].push_back(m - );
// printf("u=%d v=%d w=%d\n", u, v, w);
} void dijkstra() {
priority_queue<heapnode>que;
for (int i = ; i <= tot; i++) d[i] = inf64;
for(int i=;i<=q;i++)
{
int id = lefta[start[i] + n];
d[id] = ;
que.push(heapnode(, id));
}
memset(vis, , sizeof(vis));
while (!que.empty()) {
heapnode x = que.top(); que.pop();
int u = x.u;
// printf("u=%d\n", u);
if (vis[u]) continue;
vis[u] = ;
for (int i = ; i < g[u].size(); i++) {
edge &e = vec[g[u][i]];
// printf("u=%d e.to=%d e.dist=%d\n", u, e.to, e.dist);
// printf("d[%d]=%lld d[%d]=%lld\n", u, d[u], e.to, d[e.to]);
if (d[e.to] > d[u] + e.dist) {
// printf("ww\n");
d[e.to] = d[u] + e.dist;
// printf("d[%d]=%lld\n", e.to, d[e.to]);
que.push(heapnode(d[e.to], e.to));
}
}
// printf("\n");
}
} void builda(int id, int l, int r) {
numa[id] = ++tot;
int mid = (l + r) >> ;
if (l == r) {
lefta[l] = tot;
return;
}
builda(id << , l, mid);
builda(id << | , mid + , r);
add(numa[id << ], numa[id], );
add(numa[id << | ], numa[id], );
} void buildb(int id, int l, int r) {
numb[id] = ++tot;
int mid = (l + r) >> ;
if (l == r) {
leftb[l] = tot;
return;
}
buildb(id << , l, mid);
buildb(id << | , mid + , r);
add(numb[id], numb[id << ], );
add(numb[id], numb[id << | ], );
} void build3(int n) {
for (int i = ; i <= n; i++) add(leftb[i], lefta[i], );
} void update(int id, int l, int r, int x, int y, vector<int>&d) {
if (x <= l && y >= r) {
d.push_back(id);
return;
}
int mid = (l + r) >> ;
if (x <= mid) update(id << , l, mid, x, y, d);
if (y > mid) update(id << | , mid + , r, x, y, d);
}
vector<int>a, b;
int main()
{
scanf("%d%d%d%d", &n, &m, &p, &q);
builda(, , * n), buildb(, , * n), build3( * n);
tot++;
for (int i = ; i <= m; i++) {
int x1, y1, x2, y2, w;
scanf("%d%d%d%d%d", &x1, &y1, &x2, &y2, &w);
a.clear(), b.clear();
update(, , * n, x1, y1, a);
update(, , * n, x2 + n, y2 + n, b);
int lena = a.size(), lenb = b.size();
for(int j=;j<lena;j++)
{
int id = numa[a[j]];
add(id, tot, );
}
add(tot, tot + , w);
for(int j=;j<lenb;j++)
{
int id = numb[b[j]];
add(tot + , id, );
}
tot += ;
for(int j=;j<lenb;j++)
{
int id = numa[b[j]];
add(id, tot, );
}
add(tot, tot + , w);
for(int j=;j<lena;j++)
{
int id = numb[a[j]];
add(tot + , id, );
}
tot += ;
}
for (int i = ; i <= p; i++) scanf("%d", &endss[i]);
for (int i = ; i <= q; i++) scanf("%d", &start[i]);
dijkstra();
ll ans = ;
for(int i=;i<=p;i++)
{
int id = lefta[endss[i]];
ans = max(ans, d[id]);
}
if (ans >= inf64) printf("boring game\n");
else printf("%lld\n", ans);
return ;
}

G. 神圣的 F2 连接着我们 线段树优化建图+最短路的更多相关文章
- CodeForces 786B Legacy(线段树优化建图+最短路)
[题目链接] http://codeforces.com/problemset/problem/786/B [题目大意] 给出一些星球,现在有一些传送枪,可以从一个星球到另一个星球, 从一个星球到另一 ...
- Codeforces.786B.Legacy(线段树优化建图 最短路Dijkstra)
题目链接 \(Description\) 有\(n\)个点.你有\(Q\)种项目可以选择(边都是有向边,每次给定\(t,u,v/lr,w\)): t==1,建一条\(u\to v\)的边,花费\(w\ ...
- 【BZOJ4276】[ONTAK2015]Bajtman i Okrągły Robin 线段树优化建图+费用流
[BZOJ4276][ONTAK2015]Bajtman i Okrągły Robin Description 有n个强盗,其中第i个强盗会在[a[i],a[i]+1],[a[i]+1,a[i]+2 ...
- BZOJ_4276_[ONTAK2015]Bajtman i Okrągły Robin_线段树优化建图+最大费用最大流
BZOJ_4276_[ONTAK2015]Bajtman i Okrągły Robin_线段树优化建图+最大费用最大流 Description 有n个强盗,其中第i个强盗会在[a[i],a[i]+1 ...
- 洛谷3783 SDOI2017 天才黑客(最短路+虚树+边转点+线段树优化建图)
成功又一次自闭了 怕不是猪国杀之后最自闭的一次 一看到最短路径. 我们就能推测这应该是个最短路题 现在考虑怎么建图 根据题目的意思,我们可以发现,在本题中,边与边之间存在一些转换关系,但是点与点之间并 ...
- 【2019.7.26 NOIP模拟赛 T3】化学反应(reaction)(线段树优化建图+Tarjan缩点+拓扑排序)
题意转化 考虑我们对于每一对激活关系建一条有向边,则对于每一个点,其答案就是其所能到达的点数. 于是,这个问题就被我们搬到了图上,成了一个图论题. 优化建图 考虑我们每次需要将一个区间向一个区间连边. ...
- Nowcoder Hash Function ( 拓扑排序 && 线段树优化建图 )
题目链接 题意 : 给出一个哈希表.其避免冲突的方法是线性探测再散列.现在问你给出的哈希表是否合法.如果合法则输出所有元素插入的顺序.如果有多解则输出字典序最小的那一个.如果不合法则输出 -1 分析 ...
- bzoj5017 [Snoi2017]炸弹 (线段树优化建图+)tarjan 缩点+拓扑排序
题目传送门 https://lydsy.com/JudgeOnline/problem.php?id=5017 题解 这个题目方法挺多的. 线段树优化建图 线段树优化建图的做法应该挺显然的,一个炸弹能 ...
- 7月13日考试 题解(DFS序+期望+线段树优化建图)
T1 sign 题目大意:给出一棵 N 个节点的树,求所有起点为叶节点的有向路径,其 上每一条边权值和的和.N<=10000 水题.考试的时候毒瘤出题人(学长orz)把读入顺序改了一下,于是很多 ...
随机推荐
- Pormetheus(一)
(1)Prometheus由来普罗米修斯的灵感来自于谷歌的Borgmon.它最初是由马特·t·普劳德(Matt T. Proud)作为一个研究项目开发的,普劳德曾是谷歌(google)的一名雇员.在普 ...
- kworkerds 挖矿木马简单分析及清理
公司之前的开发和测试环境是在腾讯云上,部分服务器中过一次挖矿木马 kworkerds,本文为我当时分析和清理木马的记录,希望能对大家有所帮助. 现象 top 命令查看,显示 CPU 占用 100%,进 ...
- 安装python3.8和python2.7
在同一台电脑上同时安装Python2和Python3 目前Python的两个版本Python2和Python3同时存在,且这两个版本同时在更新与维护. 到底是选择Python2还是选择Python3, ...
- ATcoder E - Flatten 质因子分解求LCM
题解:其实就是求n个数的lcm,由于数据特别大,求lcm时只能用质因子分解的方法来求. 质因子分解求lcm.对n个数每个数都进行质因子分解,然后用一个数组记录某个质因子出现的最大次数.然后累乘pow( ...
- [PHP]听说随机数mt_rand()比rand()速度快,闲的无聊测试了一下!
废话不说上码 //microtime() 函数返回当前 Unix 时间戳的微秒数.//当设置为 TRUE 时,规定函数应该返回一个浮点数,否则返回一个字符串.默认为 FALSE. <?php h ...
- Springboot:配置文件位置以及多环境配置(六)
配置文件位置 Springboot配置文件可以加载以下四个位置: file:./config/ #第一加载位置 file:./ #第二加载位置 classpath:/config/ #第三加载位置 c ...
- mongoDB(一)——mongoDB安装部署和常用shell命令
1.mongoDB简介 mongoDB 是由C++语言编写的,是一种分布式的面向文档存储的开源nosql数据库.nosql是Not Only SQL的缩写,是对不同于传统的关系型数据库的数据库管理系统 ...
- WTF Python:有趣且鲜为人知的Python特性
Python 是一个设计优美的解释型高级语言,它提供了很多能让程序员感到舒适的功能特性.但有的时候,Python 的一些输出结果对于初学者来说似乎并不是那么一目了然. 这个有趣的项目意在收集 Pyth ...
- 用 Python 黄图批量鉴别审核
前言 最近写了一款微信小程序需要用到图片审核,人工审核是不可能的人工审核的太费精力了,所以我就写了一个多线程批量识别脚本来处理,主要是调用百度AI的接口,这里我是付费了也不贵审核一条1分钱不到,再说我 ...
- 一、搭建SpringBoot2.0.0M4基础Web项目
本次开发环境为: 系统:Linux Mint 18 JDK:1.8 开发工具:IntelliJ IDEA 2017.2.4 1.启动IDEA工具,开始创建一个基础项目.点击Create New Pro ...