听说正解是啥 set启发式合并+维护凸包+二分 根本不会啊 , 只会 李超线段树合并 啦 ... 题意 给你一颗有 \(n\) 个点的树 , 每个节点有两个权值 \(a_i, b_i\) . 从 \(u\) 跳到 \(v\) 的代价是 \(a_u \times b_v\) . 你需要计算每个节点跳到叶子的最小代价 . \((n \le 10^5, -10^5 \le a_i, b_i \le 10^5)\) 题解 我们首先考虑一个很容易的 \(dp\) , 令 \(dp_i\) 为 \(i\)…
Codeforces 题面传送门 & 洛谷题面传送门 个人感觉这题称不上毒瘤. 首先看到选一条路径之类的字眼可以轻松想到点分治,也就是我们每次取原树的重心 \(r\) 并将路径分为经过重心和不经过重心两类路径.对于第二类路径我们肯定可以在对 \(r\) 所有子树进一步分治的过程中将其变成第一类路径,因此我们只用考虑怎样计算第一类路径的贡献即可. 显然对于一条第一类路径 \(x\to y\),我们要将其拆成 \(x\to r\) 和 \(r\to y\) 两部分分别处理,考虑怎样合并这两部分的贡献…
Codeforces 题面传送门 & 洛谷题面传送门 这是一道李超线段树的毒瘤题. 首先我们可以想到一个非常 trivial 的 DP:\(dp_{i,j}\)​ 表示前 \(i\)​ 个数划分成 \(j\)​ 段的最小代价,那么显然 \(dp_{i,j}=\min\limits_{l<i}\{dp_{l,j-1}+(i-l)·\max\limits_{t=l+1}^ia_t\}\),这样暴力 DP 是 \(n^2k\) 的,一脸过不去. 考虑优化,注意到这里涉及一个 \(\max\),注意…
题目链接:CF - R296 - d2 - D 题目大意 一个特殊的图,一些数轴上的点,每个点有一个坐标 X,有一个权值 W,两点 (i, j) 之间有边当且仅当 |Xi - Xj| >= Wi + Wj. 求这个图的最大团. 图的点数 n <= 10^5. 题目分析 两点之间右边满足 Xj - Xi >= Wi + Wj (Xi < Xj)       ==>     Xj  - Wj >= Xi + Wi (Xi < Xj) 按照坐标 x 从小到大将点排序.用…
https://codeforces.com/contest/893/problem/F 题意: 给一个有根树, 多次查询,每次查询对于$x$i点的子树中,距离$x$小于等于$k$的所有点中权值最小的一个 查询强制在线 题解: 显然,暴力就是,对于每次搜索深搜距离x小于$k$的所有点搜索 那么我们考虑优化 首先,查询对$x$距离小于$k$的所有点,等价于在整颗树上,查询$\forall dep(x)≤dep(i)≤dep(x)+k$中,在$x$子树中的点的最小值 那么,一个大胆的想法就是,对于每…
洛谷 Codeforces 这是一个非正解,被正解暴踩,但它还是过了. 思路 首先很容易想到DP. 设\(dp_{x,i}\)表示\(x\)子树全部被覆盖,而且向上恰好延伸到\(dep=i\)的位置,的最小费用. 转移方程非常显然:每次把\(dp_x\)和\(dp_v\)合并时\(dp_{x,i}+=\min\{dp_v\},dp_{v,i}+=\min\{dp_x\}\),然后对应位置取\(\min\)即可. 显然这东西可以用线段树合并维护,就做完了. 然而这题卡空间,需要垃圾回收. 线段树合…
将所有串(包括S)放一块建SAM.对于询问,倍增定位出该子串所在节点,然后要查询的就是该子串在区间内的哪个字符串出现最多.可以线段树合并求出该节点在每个字符串中的出现次数. #include<bits/stdc++.h> using namespace std; #define ll long long #define N 1100010 char getc(){char c=getchar();while ((c<'A'||c>'Z')&&(c<'a'||c…
B. Prison Transfer Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/problemset/problem/427/B Description The prison of your city has n prisoners. As the prison can't accommodate all of them, the city mayor has decided to transfer c…
链接: https://codeforces.com/contest/1263/problem/E 题意: The development of a text editor is a hard problem. You need to implement an extra module for brackets coloring in text. Your editor consists of a line with infinite length and cursor, which point…
题目链接:http://codeforces.com/contest/620/problem/E E. New Year Tree time limit per test 3 seconds memory limit per test 256 megabytes input standard input output standard output The New Year holidays are over, but Resha doesn't want to throw away the N…