D. Legacy time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Rick and his co-workers have made a new radioactive formula and a lot of bad guys are after them. So Rick wants to give his legacy…
D. Legacy time limit per test:2 seconds memory limit per test:256 megabytes input:standard input output:standard output Rick and his co-workers have made a new radioactive formula and a lot of bad guys are after them. So Rick wants to give his legacy…
题意: 有n个点,q个询问, 每次询问有一种操作. 操作1:u→[l,r](即u到l,l+1,l+2,...,r距离均为w)的距离为w: 操作2:[l,r]→u的距离为w 操作3:u到v的距离为w 最终求起点到其他点的最短距离,到达不了输出-1 题解 线段树优化建图+最短路... 不知道这种东西,百度了一下,好像最早的是POI2015的PUS,然后2017/2018的oi也都出过, 还是要见识一下的... 顺便记录一下,封装好的djisktra和graph 代码如下: #include <bit…
题意: 有\(n(1 \leq n \leq 10^5)\)个点,\(q(1 \leq q \leq 10^5)\)条路和起点\(s\) 路有三种类型: 从点\(v\)到点\(u\)需要花费\(w\) 从点\(v\)到区间\([l,r]\)中的点花费为\(w\) 从区间\([l,r]\)中的点到点\(v\)花费为\(w\) 求起点到各个点的最少花费 分析: 如下图,构建两颗线段树,边的花费都为\(0\) 对于第一种路直接加边即可 对于第二种路,添加从\(v\)到上面线段树对应区间中的点的边 对于…
B. Legacy 题目连接: http://codeforces.com/contest/786/problem/B Description Rick and his co-workers have made a new radioactive formula and a lot of bad guys are after them. So Rick wants to give his legacy to Morty before bad guys catch them. There are…
Problem 遗产 题目大意 给出一个带权有向图,有三种操作: 1.u->v添加一条权值为w的边 2.区间[l,r]->v添加权值为w的边 3.v->区间[l,r]添加权值为w的边 求st点到每个点的最短路 Solution 首先我们思考到,若是每次对于l,r区间内的每一个点都执行一次加边操作,不仅耗时还耗空间. 那么我们要想到一个办法去优化它.一看到lr区间,我们就会想到线段树对吧. 没错啦这题就是用线段树去优化它. 首先我们建一棵线段树,然后很容易想到,我们只需要把这一棵线段树当做…
线段树优化连边 要求点 \(x\) 向区间 \([L, R]\) 连边, 一次的复杂度上限为 \(O(n)\) 然后弄成线段树的结构 先父子连边边权为 \(0\) 这样连边就只需要连父亲就可以等效于连了区间内每个点 空间复杂度为线段树大小, 一次区间连边时间复杂度为 \(O(\log n)\) 这是连入边, 连出边的话反向建线段树内边即可 CF786B Legacy 默认情况下他不能用这把枪开启任何传送门.在网络上有q个售卖这些传送枪的使用方案.每一次你想要实施这个方案时你都可以购买它,但是每次…
B. Legacy 题目连接: http://codeforces.com/contest/786/problem/B Description Rick and his co-workers have made a new radioactive formula and a lot of bad guys are after them. So Rick wants to give his legacy to Morty before bad guys catch them. There are…
D. Legacy time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Rick and his co-workers have made a new radioactive formula and a lot of bad guys are after them. So Rick wants to give his legacy…
题意:给N个点和Q条选项,有三种类型的选项:1.从u到v花费w修建一条路:2.从u到下标区间为[L,R]的点花费w修建一条路; 3.从下标区间为[L,R]的点到u花费w修建一条路. 然后求起点s到其余点的最短路. 如果直接暴力建图,建图本身就会超时.对于区间上的操作,考虑用线段树解决.线段树上的结点本身就能代表一段区间的点,所以在建图时,用树上的结点充当中间结点.(有点网络流的思想?) 因为要建一张有向图,所以图的点到树上结点要连边,反之亦然:但是在一棵线段树上双向连边就不能对所有的点跑最短路了…