[Luogu] 网络
https://www.luogu.org/problemnew/show/P3250
树链剖分 + 线段树 + 优先队列
要求未被影响的请求中最大的
所以每次将每条路径在整棵树上的补集的每个节点的优先队列加入该路径的权值
mid 敲错调了一上午
气炸。。。
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <string>
#include <queue>
#include <vector> using namespace std;
const int N = 1e5 + ; #define yxy getchar()
#define lson jd << 1
#define rson jd << 1 | 1 #define RR freopen("gg.in", "r", stdin) int n, Ty, Tim, how, ans;
int fa[N], topp[N], deep[N], size[N], son[N], tree[N];
priority_queue <int> Q1[N << ], Q2[N << ];
vector <int> vec[N << ];
struct Node{int up, down;} D[N];
struct Node2{int l, r, val;} Ask[N << ]; inline int read() {
int x = ; char c = yxy;
while(c < '' || c > '') c = yxy;
while(c >= '' && c <= '') x = x * + c - '', c = yxy;
return x;
} void Dfs_son(int u, int f_, int dep) {
fa[u] = f_;
deep[u] = dep;
size[u] = ;
int siz_ = vec[u].size();
for(int i = ; i < siz_; i ++) {
int v = vec[u][i];
if(v != f_) {
Dfs_son(v, u, dep + );
size[u] += size[v];
if(size[v] > size[son[u]]) son[u] = v;
}
}
} void Dfs_un(int u, int tp) {
topp[u] = tp;
tree[u] = ++ Tim;
if(!son[u]) return ;
Dfs_un(son[u], tp);
int siz_ = vec[u].size();
for(int i = ; i < siz_; i ++) {
int v = vec[u][i];
if(v != fa[u] && v != son[u]) Dfs_un(v, v);
}
} inline bool cmp(Node a, Node b) {return a.up < b.up;} void Sec_G(int l, int r, int jd, int x, int y, int yj) {
if(x <= l && r <= y) {
if(how == ) Q1[jd].push(yj);
else Q2[jd].push(yj);
return ;
}
int mid = (l + r) >> ;
if(x <= mid) Sec_G(l, mid, lson, x, y, yj);
if(y > mid) Sec_G(mid + , r, rson, x, y, yj);
} inline void Sec_G_imp(int x, int y, int val) {
int tp1 = topp[x], tp2 = topp[y], js();
while(tp1 != tp2) {
if(deep[tp1] < deep[tp2]) swap(x, y), swap(tp1, tp2);
D[++ js].up = tree[tp1];
D[js].down = tree[x];
x = fa[tp1];
tp1 = topp[x];
}
if(deep[x] < deep[y]) swap(x, y);
D[++ js].up = tree[y]; D[js].down = tree[x];
sort(D + , D + js + , cmp);
int last = ;
for(int i = ; i <= js; i ++) {
int l_ = last + , r_ = D[i].up - ;
if(l_ <= r_) Sec_G(, n, , l_, r_, val);
last = D[i].down;
}
int l_ = last + , r_ = n;
if(l_ <= r_) Sec_G(, n, , l_, r_, val);
} int get_answer(int jd) {
int ret = -;
while(!Q2[jd].empty() && (Q1[jd].top() == Q2[jd].top())) Q1[jd].pop(), Q2[jd].pop();
if(Q1[jd].empty()) return -;
return Q1[jd].top();
} void Sec_A(int l, int r, int jd, int x) {
ans = max(ans, get_answer(jd));
if(l == r) return ;
int mid = (l + r) >> ;
if(x <= mid) Sec_A(l, mid, lson, x);
else Sec_A(mid + , r, rson, x);
} int main() {
n = read();
Ty = read();
for(int i = ; i < n; i ++) {
int u = read(), v = read();
vec[u].push_back(v);
vec[v].push_back(u);
}
Dfs_son(, , );
Dfs_un(, );
for(int i = ; i <= Ty; i ++) {
int opt = read();
if(opt == ) { //添加
Ask[i].l = read(), Ask[i].r = read(), Ask[i].val = read();
how = ;
Sec_G_imp(Ask[i].l, Ask[i].r, Ask[i].val);
} else if(opt == ) { //删除
int x = read();
how = -;
Sec_G_imp(Ask[x].l, Ask[x].r, Ask[x].val);
} else { //查询
int x = read();
ans = -;
Sec_A(, n, , tree[x]);
cout << ans << endl;
}
}
return ;
}
[Luogu] 网络的更多相关文章
- [Luogu 2604] ZJOI2010 网络扩容
[Luogu 2604] ZJOI2010 网络扩容 第一问直接最大流. 第二问,添加一遍带费用的边,边权 INF,超级源点连源点一条容量为 \(k\) 的边来限流,跑费用流. 大约是第一次用 nam ...
- luogu 1327 数列排序 & 2017 ACM-ICPC 亚洲区(南宁赛区)网络赛 J题 循环节
luogu 1327 数列排序 题意 给定一个数列\(\{an\}\),这个数列满足\(ai≠aj(i≠j)\),现在要求你把这个数列从小到大排序,每次允许你交换其中任意一对数,请问最少需要几次交换? ...
- BZOJ 1834 Luogu P2604 [ZJOI2010]网络扩容 (最小费用最大流)
题目连接: (luogu) https://www.luogu.org/problemnew/show/P2604 (bzoj) https://www.lydsy.com/JudgeOnline/p ...
- P3376 【模板】网络最大流(luogu)
P3376 [模板]网络最大流(luogu) 最大流的dinic算法模板(采取了多种优化) 优化 时间 inline+当前弧+炸点+多路增广 174ms no 当前弧 175ms no 炸点 249 ...
- 【Luogu P3376】网络最大流
Luogu P3376 最大流是网络流模型的一个基础问题. 网络流模型就是一种特殊的有向图. 概念: 源点:提供流的节点(入度为0),类比成为一个无限放水的水厂 汇点:接受流的节点(出度为0),类比成 ...
- LOJ #2547 Luogu P4517「JSOI2018」防御网络
好像也没那么难写 LOJ #2547 Luogu P4517 题意 在一棵点仙人掌中等概率选择一个点集 求选出点集的斯坦纳树大小的期望 定义点仙人掌为不存在一个点在多个简单环中的连通图 斯坦纳树为在原 ...
- Luogu P2002 消息扩散&&P1262 间谍网络
怕自己太久没写Tarjan了就会把这种神仙算法忘掉. 其实这种类型的图论题的套路还是比较简单且显然的. P2002 消息扩散 很显然的题目,因为在一个环(其实就是强连通分量)中的城市都只需要让其中一个 ...
- 【题解】Luogu P2604 [ZJOI2010]网络扩容
原题传送门:P2604 [ZJOI2010]网络扩容 这题可以说是板题 给你一个图,先让你求最大流 再告诉你,每条边可以花费一些代价,使得流量加一 问至少花费多少代价才能使最大流达到k 解法十分简单 ...
- 【luogu P1262 间谍网络】 题解
题目链接:https://www.luogu.org/problemnew/show/P1262 注意: 1.缩点时计算出入度是在缩完点的图上用color计算.不要在原来的点上计算. 2.枚举出入度时 ...
随机推荐
- 15_IO流
IO流 流 流的概念 流(stream)是指一连串流动字节/字符,按照先进先出的方式发送的信息的通道中. 数据源:流入通道中的数据的来源 目的地:流出通道的数据的目的地 输入流和输出流 数据源的数 ...
- 应用人员反馈报错,ORA-03137: TTC protocol internal error : [12333]
一.报错现象 应用人员反馈连接不上数据库,连接报错. 我们使用PLSQL发现可以连接数据库,但是数据库DB Alert存在如下报错信息 DB AlertFri Oct :: Errors ): ORA ...
- (四)springmvc之获取servlet原生对象
一.使用DI注入的方式 <a href="<%=request.getContextPath()%>/servletObj_1">DI注入的方式</a ...
- android 仿微信朋友圈图片选择控件
调用方式(布局文件就是一个自定义控件): private ArrayList<String> selectedImages; @BindView(R.id.imagePicker) Ima ...
- C# Combox控件绑定自定义数据
DataTable dt = new DataTable(); dt.Columns.Add("name"); dt.Columns.A ...
- iOS-OC中常见的一些宏
/* 1. 颜色 */ #define PCBRGBColorA(r, g, b, a) [UIColor colorWithRed:(r)/255.0 green:(g)/255.0 blue:(b ...
- 你不知道的javascript(上卷)读后感(一)
三剑客 编译,顾名思义,就是源代码执行前会经历的过程,分三个步骤, 分词/词法分析,将我们写的代码字符串分解成多个词法单元 解析/语法分析,将词法单元集合生成抽象语法树(AST) 代码生成,抽象语法树 ...
- IE浏览器下载后台返回的Excel文件,报错400
问题描述(见下图): 问题分析: 400是后端没有接收到请求 原因是后端高版本的tomcat不会自动对字符串进行转义 所以,前端把参数值进行转义,即encodeURI(string) 问题处理前代码( ...
- 《浏览器工作原理与实践》<10>作用域链和闭包 :代码中出现相同的变量,JavaScript引擎是如何选择的?
在上一篇文章中我们讲到了什么是作用域,以及 ES6 是如何通过变量环境和词法环境来同时支持变量提升和块级作用域,在最后我们也提到了如何通过词法环境和变量环境来查找变量,这其中就涉及到作用域链的概念. ...
- Paper Reading:Receptive Field Block Net for Accurate and Fast Object Detection
论文:Receptive Field Block Net for Accurate and Fast Object Detection 发表时间:2018 发表作者:(Beihang Universi ...